各位,谁知道如何调用windows系统自带的copy,paste,cut???????? String text="some text to copy";Clipboard.SetDataObject(text); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 呵呵~~~~你是说想调用系统的copy,paste,cut吧?太难了,偶不会,不过,帮你搜到:http://www.donews.net/zwell/articles/30698.aspx希望你不头大:)不过,要是用就这三个的话,你可以直接写代码呀。 IDataObject clipboardData=Clipboard.GetDataObject();String text;if(clipboardData.GetDataPresent(DataFormats.Text)){text=(String)clipboardData.GetData(DataFormats.Text);} Clipboard。如果是控制richtextbox的话就可以直接调用richtextbox的方法:richtextbox.Cut();richtextbox.Copy();richtextbox.Paste(); 先做个paste的例子using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace WindowsApplication6{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.ContextMenu contextMenu1; private System.Windows.Forms.MenuItem menuItem1; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; //粘贴剪切板 [System.Runtime.InteropServices.DllImport("user32")] private static extern IntPtr SetClipboardViewer(IntPtr hwnd); [System.Runtime.InteropServices.DllImport("user32")] private static extern IntPtr ChangeClipboardChain(IntPtr hwnd,IntPtr hWndNext); [System.Runtime.InteropServices.DllImport("user32")] private static extern int SendMessage(IntPtr hwnd,int wMsg,IntPtr wParam,IntPtr lParam); const int WM_DRAWCLIPBOARD = 0x308; const int WM_CHANGECBCHAIN = 0x30D; IntPtr NextClipHwnd; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.contextMenu1 = new System.Windows.Forms.ContextMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.SuspendLayout(); // // richTextBox1 // this.richTextBox1.ContextMenu = this.contextMenu1; this.richTextBox1.Location = new System.Drawing.Point(20, 12); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(218, 168); this.richTextBox1.TabIndex = 0; this.richTextBox1.Text = "richTextBox1"; // // contextMenu1 // this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.Text = "粘贴"; this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.richTextBox1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void menuItem1_Click(object sender, System.EventArgs e) { NextClipHwnd=SetClipboardViewer(this.Handle); ChangeClipboardChain(this.Handle,NextClipHwnd); //从观察链中删除本观察窗口 SendMessage(NextClipHwnd,WM_CHANGECBCHAIN,this.Handle,NextClipHwnd); } //剪切板 protected override void WndProc(ref System.Windows.Forms.Message m) { switch(m.Msg) { case WM_DRAWCLIPBOARD: SendMessage(NextClipHwnd,m.Msg,m.WParam,m.LParam); //将WM_DRAWCLIPBOARD消息传递到下一个观察链中的窗口 IDataObject iData = Clipboard.GetDataObject(); if(iData.GetDataPresent(DataFormats.Text)|iData.GetDataPresent(DataFormats.OemText)) { this.richTextBox1.Rtf =(String)iData.GetData(DataFormats.Rtf); } break; default: base.WndProc(ref m); break; } } }} 我觉得粘贴,复制,剪切,这些系统常用的东西,或许能有个便捷的现成方法,就像点击鼠标右键弹出的那个菜单一样,如果能把右键菜单的功能放在Menu上,就搞定了:)前面的朋友提到richtextbox可以用现成的方法;其他的可输入控件是不是都可以??我是想将功能做在主menu上,所以不能只调用一个控件的方法,大家帮忙!:) 其实menu也是对应着一个对象的, 鼠标右键的context menu还不是在一个对象里触发后也会不一样吗你要做的是获取当前的对象,然后调用Clipboard的方法 复制:object s = "看看";Clipboard.SetDataObject(s.ToString());粘贴:IDataObject iData = Clipboard.GetDataObject(); // Determines whether the data is in a format you can use.if(iData.GetDataPresent(DataFormats.Text)) { // Yes it is, so display it in a text box. this.richTextBox1.Text = (String)iData.GetData(DataFormats.Text); }帮助里搜索Clipboard看看使用方法 问一个也许很弱的问题,关于异步回调的 获取HttpWebResponse响应的页面字符集 如何实现自动入住 如何获取多表查询的表结构信息? 请帮我一下 这有一段C#代码,有一些错误,大家帮我分析一下 c# 数值分析 一个小问题 怎样用多线程绑定WinForm中的DataGrid数据 谁能给我解析下这奇葩语法? 请教:怎么取nt系统当前用户名(c#) GetProcessesByName调用无法实现
太难了,偶不会,不过,帮你搜到:
http://www.donews.net/zwell/articles/30698.aspx希望你不头大:)不过,要是用就这三个的话,你可以直接写代码呀。
String text;if(clipboardData.GetDataPresent(DataFormats.Text))
{
text=(String)clipboardData.GetData(DataFormats.Text);
}
richtextbox.Copy();
richtextbox.Paste();
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication6
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
//粘贴剪切板
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr SetClipboardViewer(IntPtr hwnd);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr ChangeClipboardChain(IntPtr hwnd,IntPtr hWndNext);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern int SendMessage(IntPtr hwnd,int wMsg,IntPtr wParam,IntPtr lParam); const int WM_DRAWCLIPBOARD = 0x308;
const int WM_CHANGECBCHAIN = 0x30D;
IntPtr NextClipHwnd;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.ContextMenu = this.contextMenu1;
this.richTextBox1.Location = new System.Drawing.Point(20, 12);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(218, 168);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "richTextBox1";
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "粘贴";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void menuItem1_Click(object sender, System.EventArgs e)
{
NextClipHwnd=SetClipboardViewer(this.Handle);
ChangeClipboardChain(this.Handle,NextClipHwnd);
//从观察链中删除本观察窗口
SendMessage(NextClipHwnd,WM_CHANGECBCHAIN,this.Handle,NextClipHwnd);
}
//剪切板
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch(m.Msg)
{
case WM_DRAWCLIPBOARD:
SendMessage(NextClipHwnd,m.Msg,m.WParam,m.LParam);
//将WM_DRAWCLIPBOARD消息传递到下一个观察链中的窗口
IDataObject iData = Clipboard.GetDataObject();
if(iData.GetDataPresent(DataFormats.Text)|iData.GetDataPresent(DataFormats.OemText))
{
this.richTextBox1.Rtf =(String)iData.GetData(DataFormats.Rtf);
}
break;
default:
base.WndProc(ref m);
break;
}
}
}
}
前面的朋友提到richtextbox可以用现成的方法;其他的可输入控件是不是都可以??
我是想将功能做在主menu上,所以不能只调用一个控件的方法,大家帮忙!:)
鼠标右键的context menu还不是在一个对象里触发后也会不一样吗
你要做的是获取当前的对象,然后调用Clipboard的方法
object s = "看看";
Clipboard.SetDataObject(s.ToString());
粘贴:
IDataObject iData = Clipboard.GetDataObject();
// Determines whether the data is in a format you can use.
if(iData.GetDataPresent(DataFormats.Text))
{
// Yes it is, so display it in a text box.
this.richTextBox1.Text = (String)iData.GetData(DataFormats.Text);
}帮助里搜索Clipboard看看使用方法