在C#中使用剪贴板功能
作者:techmango 日期:2009-01-14
我们平时在电脑上最常用的操作要算是复制,粘贴了吧,那么这个复制了的信息就是放在剪贴板里的,这也算是一块内存区域了,而在C#中,就有一个Clipboard类,用它可以方便地操作剪贴板里的信息.
复制:
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);
}
粘贴:
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);
}
}
很简单吧,这就是通过调用C#中Clipborad的API完成的。
文章来自: 本站原创
Tags: C# 剪贴板 Clipboard 内存
上一篇
下一篇
