Question : vb.net copy image from clipboard to image control

How can copy image from clipboard and paste to image control

Answer : vb.net copy image from clipboard to image control

Private Sub cmdLoadImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoadImage.Click
       'loading image into the picture box
        LoadImage()
   End Sub

   Private Sub cmdCopyImage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCopyImage.Click
       'copying image to clipboard from picturebox
       CopyImage()
   End Sub

   Private Sub cmdPasteImage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPasteImage.Click
       'pasting copied image back to the picturebox
       PasteImage()
   End Sub

   Private Sub cmdClearImage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdClearImage.Click
       'clear picturebox image
       ClearImage()
   End Sub

   Public Sub ClearImage()
       'clear image from picturebox
       PictureBox1.CreateGraphics.Clear(Color.White)
   End Sub

   Public Sub PasteImage()
       'check the data format in clipboard if its of type bitmap then proceed further
        If Clipboard.GetDataObject.GetDataPresent(DataFormats.Bitmap) Then
           'setting clipboard data to picturebox
           PictureBox1.Image = Clipboard.GetDataObject.GetData(DataFormats.Bitmap)
       End If
   End Sub
   Public Sub CopyImage()
       'copy image to clipboard
       'setting picturebox data to clipboard
       Clipboard.SetDataObject(PictureBox1.Image)
   End Sub

   Public Sub LoadImage()
       'shows OPEN FILE DIALOG for locating graphic files on the harddisk
        'setting visible file filter
       OFD.Filter = "Images | *.bmp;*.tif;*.jpg;*.gif"
       'Show OPEN FILE DIALOG to user
       OFD.ShowDialog()
       'Load located file to  the picturebox
       PictureBox1.Image = Image.FromFile(OFD.FileName)
   End Sub
   Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

       'Short cut keys implementation
        If e.Control And e.KeyCode = Keys.C Then
           CopyImage()
       End If
       If e.Control And e.KeyCode = Keys.L Then
           LoadImage()
       End If
       If e.Control And e.KeyCode = Keys.V Then
           PasteImage()
       End If
       If e.Control And e.KeyCode = Keys.R Then
           ClearImage()
       End If


   End Sub

Random Solutions  
 
programming4us programming4us