1. 为传送数据提供与格式无关的机制。
2. IDataObject 方法:
- GetData(String):检索指定格式的数据对象;数据格式由字符串指定。
- GetData(Type):检索指定格式的数据对象;数据格式由 Type 对象指定。
- GetDataPresent(Type): 查看是否具有指定格式的数据,或者数据是否可以转换为指定格式。 数据格式由 Type 对象指定。DataFormats 类的字段。
IDataObject d = Clipboard.GetDataObject(); //从剪贴板上获取对象
if (d.GetDataPresent(DataFormats.Text))
{
textBox1.Text = (string)d.GetData(DataFormats.Text); //粘贴剪贴板上的文字
}
1 private void button1_Click(object sender, EventArgs e)
2 {
3 OpenFileDialog of = new OpenFileDialog();
4 of.Filter = "Bmp File(*.bmp)|*.bmp|jpg File(*.jpg)|*.jpg|All File(*.*)|*.*";//设置文件类型
5 if (of.ShowDialog() == DialogResult.OK)
6 {
7 Bitmap image = new Bitmap(of.FileName);
8 pictureBox1.Image = image;
9 }
10 }
11
12 private void button2_Click(object sender, EventArgs e)
13 {
14 Clipboard.SetDataObject(pictureBox1.Image);
15 }
16
17 private void button3_Click(object sender, EventArgs e)
18 {
19 IDataObject d = Clipboard.GetDataObject();//从剪贴板上获取对象
20 if (d.GetDataPresent(DataFormats.Bitmap))
21 {
22 pictureBox2.Image = (Bitmap)d.GetData(DataFormats.Bitmap);
23 }
24 }