Solved

vb.net

Posted on 2004-08-09
5
386 Views
Last Modified: 2010-04-17
how to write cut copy paste code in vb.net
0
Comment
Question by:imrancs
5 Comments
 
LVL 8

Accepted Solution

by:
SNilsson earned 500 total points
Comment Utility
0
 
LVL 7

Expert Comment

by:dttri
Comment Utility
 Hello,
  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(TextBox1.Text) (VB.NET)
  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(DataFormats.Text)) Then
    TextBox1.Text = data.GetData(DataFormats.Text).ToString()
  End If

  Tri
0
 
LVL 4

Expert Comment

by:computerg33k
Comment Utility
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to adjust sheet 1 81
linearIn  challenge 23 65
My 2003 Land Rover discovery 2 key for code for car alarm 7 78
countX 22 68
This is an explanation of a simple data model to help parse a JSON feed
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now