By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,219 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,219 IT Pros & Developers. It's quick & easy.

Cut Copy Paste Undo

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
* "Keith" <an*******@discussions.microsoft.com> scripsit:
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>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

P: n/a
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(strTe xtToCopy, 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.D ataFormats.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(MyBit map, 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

=================================================
"Keith" <an*******@discussions.microsoft.com> wrote in message news:<20*****************************@phx.gbl>...
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.

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.