1 private void AcquireFromClipboard()
2 {
3 IDataObject iData = Clipboard.GetDataObject();
4 if(iData == null)
5 return;
6 Image img = null;
7 if(iData.GetDataPresent(DataFormats.Bitmap) || iData.GetDataPresent(DataFormats.MetafilePict))
8 {
9 img = (Image)iData.GetData(DataFormats.Bitmap);
10 PaintDotNet.WinGUI.Forms.ImageForm imageForm = new PaintDotNet.WinGUI.Forms.ImageForm(this);
11 PdnLib.Document doc = new PdnLib.Document(img);
12 doc.IsDirty = true;
13 imageForm.GetView().GetSurfaceBox().Document = doc;
14 this.layersDialog.BindLayerList(imageForm.GetView().GetSurfaceBox().Document.Layers);
15 imageForm.Show();
16 }
17 }
其中iData.GetDataPresent(DataFormats.MetafilePict)可以确保我的程序能够获得Office程序复制的内容2 {
3 IDataObject iData = Clipboard.GetDataObject();
4 if(iData == null)
5 return;
6 Image img = null;
7 if(iData.GetDataPresent(DataFormats.Bitmap) || iData.GetDataPresent(DataFormats.MetafilePict))
8 {
9 img = (Image)iData.GetData(DataFormats.Bitmap);
10 PaintDotNet.WinGUI.Forms.ImageForm imageForm = new PaintDotNet.WinGUI.Forms.ImageForm(this);
11 PdnLib.Document doc = new PdnLib.Document(img);
12 doc.IsDirty = true;
13 imageForm.GetView().GetSurfaceBox().Document = doc;
14 this.layersDialog.BindLayerList(imageForm.GetView().GetSurfaceBox().Document.Layers);
15 imageForm.Show();
16 }
17 }
下面给出一幅截图(程序获得了通过PrintScreen截取的绘图程序界面)