imrancs
asked on
vb.net
how to write cut copy paste code in vb.net
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(Col or.White)
End Sub
Public Sub PasteImage()
'check the data format in clipboard if its of type bitmap then proceed further
If Clipboard.GetDataObject.Ge tDataPrese nt(DataFor mats.Bitma p) Then
'setting clipboard data to picturebox
PictureBox1.Image = Clipboard.GetDataObject.Ge tData(Data Formats.Bi tmap)
End If
End Sub
Public Sub CopyImage()
'copy image to clipboard
'setting picturebox data to clipboard
Clipboard.SetDataObject(Pi ctureBox1. 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.FileNam e)
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEv entArgs) 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
'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
End Sub
Public Sub PasteImage()
'check the data format in clipboard if its of type bitmap then proceed further
If Clipboard.GetDataObject.Ge
'setting clipboard data to picturebox
PictureBox1.Image = Clipboard.GetDataObject.Ge
End If
End Sub
Public Sub CopyImage()
'copy image to clipboard
'setting picturebox data to clipboard
Clipboard.SetDataObject(Pi
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.FileNam
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEv
'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
This is from MSDN:
A number of applications use the Clipboard as a temporary repository for data. For example, word processors use it during cut/copy/paste operations. Accessing the Clipboard and storing data there with a Windows application is made possible through the use of the SetDataObject method, which stores the data on the Clipboard using the IDataObject interface. The SetDataObject method does this so that, when the data is later retrieved from the Clipboard, it can be done so in a variety of formats.
To set data to clipboard:
Clipboard.SetDataObject(Te
To paste data:
'Create a new instance of the DataObject interface.
Dim data As IDataObject = Clipboard.GetDataObject()
'If the data is text, then set the text of the
'TextBox to the text in the Clipboard.
If (data.GetDataPresent(DataF
TextBox1.Text = data.GetData(DataFormats.T
End If
Tri