What is the code to make the cut, copy, and paste buttons work? If someone could respond soon that would be helpful, thanks.
Printable View
What is the code to make the cut, copy, and paste buttons work? If someone could respond soon that would be helpful, thanks.
I did the copy and paste, I'm sure the cut is very similar.
VB Code:
Private Sub mnuCopy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuCopy.Click For Each oControl As Control In Me.Controls If oControl.Focused Then If TypeOf oControl Is TextBox Then If CType(oControl, TextBox).SelectionLength > 0 Then CType(oControl, TextBox).Copy() End If End If End If Next End Sub Private Sub mnuPaste_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPaste.Click For Each oControl As Control In Me.Controls If oControl.Focused Then If TypeOf oControl Is TextBox Then If Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) = True Then CType(oControl, TextBox).Paste() End If End If End If Next End Sub
ummmmmmm..... it didnt work
Okay, I'll use my super psychic powers to determine the exception, and I'll get back to you. Just kidding. Did you copy/paste the entire thing, or did you create your own menu click events?
wait no it does work but I still cant get the cut to work.
I made a new menu item, mnuCut. I went into my Form code and selected mnuCut, then selected the Click event, this created a new sub. I copied the code from the copy sub, pasted it into the new sub, and replaced the .Copy() with a .Cut(), and it worked.
Do you know how to get a save, load and print buttons to work??
The simplest way to code Cut, Copy and Paste is to use SendKeys.Send() to send the Ctrl+X, Ctrl+C and Ctrl+V key combinations to your appThat way you don't have to fiddle around to work out whether the correct type of control is focused and what text is selected. As far as Save, Load and Print are concerned, they mean different things to different apps, so it is up to you. You may want to use the SaveFileDialog, OpenFileDialog and PrintDialog classes in some way. To print, you will generally be using the PrintDocument class and its PrintPage event. You may also want to employ a PrintPreviewDialog.VB Code:
SendKeys.Send(^X) 'Cut. SendKeys.Send(^C) 'Copy. SendKeys.Send(^V) 'Paste.
Just a side note,... this code works better if you put quotes around the value. :D
VB Code:
Call SendKeys.Send("^C") 'Copy.
i just use the Clipboard object directly
Clipboard.SetDataObject()
Clipboard.GetDataObject()