C#怎么实现右键菜单的复制和粘贴?
我在C#窗体中打开一个html文件,想实现右键菜单的复制和粘贴功能,可以把html上的内容复制粘贴到别的地方去。求复制粘贴的实现代码或例子,谢谢!!!!...
我在C#窗体中打开一个html文件,想实现右键菜单的复制和粘贴功能,可以把html上的内容复制粘贴到别的地方去。
求复制粘贴的实现代码或例子,谢谢!!!! 展开
求复制粘贴的实现代码或例子,谢谢!!!! 展开
展开全部
给你一段代码,可以实现你要的功能
复制textbox1:
private void button1_Click(object sender, System.EventArgs e) {
// Takes the selected text from a text box and puts it on the clipboard.
if(textBox1.SelectedText != ”")
Clipboard.SetDataObject(textBox1.SelectedText);
}
粘贴到textbox2:
private void button2_Click(object sender, System.EventArgs e) {
// Declares an IDataObject to hold the data returned from the clipboard.
// Retrieves the data from the clipboard.
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.
textBox2.Text = (String)iData.GetData(DataFormats.Text);
}
}
复制textbox1:
private void button1_Click(object sender, System.EventArgs e) {
// Takes the selected text from a text box and puts it on the clipboard.
if(textBox1.SelectedText != ”")
Clipboard.SetDataObject(textBox1.SelectedText);
}
粘贴到textbox2:
private void button2_Click(object sender, System.EventArgs e) {
// Declares an IDataObject to hold the data returned from the clipboard.
// Retrieves the data from the clipboard.
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.
textBox2.Text = (String)iData.GetData(DataFormats.Text);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询