How to paste image into picturebox from clipboard with VB.Net

How to paste image into picturebox from clipboard with VB.Net
If you wish to paste an image into a picturebox from clipboard for your VB.Net project, this is what to do:
1. Add a picturebox to your form.
2. Add a button and copy paste the code below.


        Private Sub btnPastePic_Click(sender As Object, e As EventArgs) Handles btnPastePic.Click
     


        'If My.Computer.Clipboard.ContainsImage Then
        '    PictureBox1.Image = My.Computer.Clipboard.GetImage
        'End If

        Dim idata As IDataObject = Clipboard.GetDataObject()
        If idata.GetDataPresent("System.Drawing.Bitmap") Then
            Dim imgObject As Object = idata.GetData("System.Drawing.Bitmap")
            If imgObject IsNot Nothing Then
                Dim img As Image = TryCast(imgObject, Image)
                If img IsNot Nothing Then
                    PictureBox1.Image = img
                End If
            End If
        End If


   

       
    End Sub

Comments

Popular posts from this blog

CREATING CRYSTAL REPORTS VB.NET 2012 STEP BY STEP - PART 2

How to Create Crystal Report using Visual Studio 2012 Part 1