Cut Copy Paste Undo

  • Thread starter Thread starter Keith
  • Start date Start date
K

Keith

I'm trying to come up with a way to create a contextmenu
that will do all the "standard" functions (cut, copy,
paste, undo, etc).

There seems to be a lot of information out there - but
nothing seems to work for me. A few people refer to
txt.copy() txt.paste(), etc. I'm not sure if those are
old functions, but they do not work for me.

I've tried textbox1.selectall() - that works in selecting
all the text in the textbox1 that I have. However - I'm
still looking for the other functions. Then I ran across
a MSDN article - visual Studio - Placing Data on the
Clipboard. The code is as follows:

' Visual Basic
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Clipboard.SetDataObject(TextBox1.Text)
End Sub

This will place data on teh clipboard. Have not tried it
yet - looks like it will work. They also have code to
retreive the data from the clipboard.

Just wondering how everyone else creats these click events?
Also - if anyone can steer me in the right direction when
it comes to the Undo command?
Thanks.
 
* "Keith said:
I'm trying to come up with a way to create a contextmenu
that will do all the "standard" functions (cut, copy,
paste, undo, etc).

There seems to be a lot of information out there - but
nothing seems to work for me. A few people refer to
txt.copy() txt.paste(), etc. I'm not sure if those are
old functions, but they do not work for me.

I've tried textbox1.selectall() - that works in selecting
all the text in the textbox1 that I have. However - I'm
still looking for the other functions. Then I ran across
a MSDN article - visual Studio - Placing Data on the
Clipboard. The code is as follows:

' Visual Basic
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Clipboard.SetDataObject(TextBox1.Text)
End Sub

This will place data on teh clipboard. Have not tried it
yet - looks like it will work. They also have code to
retreive the data from the clipboard.

Just wondering how everyone else creats these click events?

There are no more "high-level" commands available for the textbox. You
will have to copy text to the clipboard etc. yourself.

<URL:http://dotnet.mvps.org/dotnet/samples/controls/downloads/RichTextBoxContext.zip>
 
Hi Keith,

The following Clipboard sample code should get you started in the right direction:

Hope this helps,
Dan Haught
www.fmsinc.com/dotnet
** Powered by Total .NET SourceBook **

=================================================
Sub CopyPaste()

' Shows different ways to use the Clipboard object

Dim strTextToCopy As String = "This is the text."

' Copy the text to the clipboard. By specifying False for the
' second parameter, we are saying that the text should not
' remain on the clipboard after our application exits.
System.Windows.Forms.Clipboard.SetDataObject(strTextToCopy, False)

' Create the IDataObject and get the Clipboard data into it
Dim MyDataObject As System.Windows.Forms.IDataObject = _
System.Windows.Forms.Clipboard.GetDataObject()

' Does data exist in the clipboard?
If MyDataObject.GetDataPresent(System.Windows.Forms.DataFormats.Text) Then
' Data exists, get it into a string
Dim strBuffer As String = CType(MyDataObject.GetData _
(System.Windows.Forms.DataFormats.StringFormat), String)
Console.WriteLine(New System.Text.StringBuilder( _
"The copied/pasted data is: ").Append(strBuffer).ToString())
Else
' No data exists.
Console.WriteLine("Could not get clipboard data: no data present.")
End If

' Create a bitmap object and send it to the clipboard
Dim MyBitmap As New Drawing.Bitmap("C:\windows\web\wallpaper\wind.jpg")
System.Windows.Forms.Clipboard.SetDataObject(MyBitmap, True)

' Get the clipboard data into our data object
Dim MyBinaryDataObject As System.Windows.Forms.IDataObject = _
System.Windows.Forms.Clipboard.GetDataObject()

' Diaplay the formats currently available in the clipboard
Dim strFormats() As String = MyBinaryDataObject.GetFormats(True)
Console.WriteLine("Supported formats for current clipboard data: ")

Dim i As Integer

For i = 0 To strFormats.GetUpperBound(0)
Dim formatString As System.Text.StringBuilder = New _
System.Text.StringBuilder("Format ").Append(i.ToString())
Console.WriteLine(formatString.Append(strFormats(i)))
Next

End Sub

=================================================
 
Back
Top