How to save a graphic from the Clipboard to a file by using Visual Basic .NET or Visual Basic 2005 (818410)
The information in this article applies to:
- Microsoft Visual Basic 2005
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
This article refers to the following Microsoft .NET
Framework Class Library namespace:
System.Windows.Forms.ClipboardIN THIS TASKSUMMARYThis step-by-step article describes how to save the
graphic that is loaded in the Clipboard as a bitmap file by using Visual Basic .NET or Visual Basic 2005. This
article describes how to use the Clipboard class to do
this. back to the
topCopy a Graphic from the Clipboard- Run Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
- Click
New on the File menu and then click Project.
- Rename the application to ClipBoardDemo.
- Under Project types, click Visual
Basic Projects. Under
Templates, click Windows Application and then click OK.
By
default, Form1 is created.
Note In Visual Studio 2005, click Visual Basic under Project Types. - From the Toolbox, add
a Button control to Form1.
- Right-click Form1 and then click View
Code.
- Paste the following code in the Form1 class code.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then
Dim oDataObj As IDataObject = System.Windows.Forms.Clipboard.GetDataObject()
If oDataObj.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) Then
Dim oImgObj As System.Drawing.Image = oDataObj.GetData(DataFormats.Bitmap, True)
'To Save as Bitmap
oImgObj.Save("c:\Test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
'To Save as Jpeg
oImgObj.Save("c:\Test.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
'To Save as Gif
oImgObj.Save("c:\Test.gif", System.Drawing.Imaging.ImageFormat.Gif)
End If
End If
End Sub - On the Build menu, click Build
Solution.
ClipBoardDemo.Exe is created. back to the
topVerify the Result- Run the ClipBoardDemo.exe file application.
Form1 appears. - Press PRINT SCREEN to add the
graphical image of the screen to the Clipboard.
- Click Button1.
- Three image files are
created in c:\. The image files are Test.bmp, Test.gif, and Test.jpeg.
- Open c:\Test.bmp in Microsoft Paint. Verify the Print
Screen image is present in the Test.bmp file.
back to the
top
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005applies kbWindowsForms kbClipboard kbHOWTOmaster kbhowto KB818410 kbAudDeveloper |
---|
|