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.IDataObje ct = _
System.Windows. Forms.Clipboard .GetDataObject( )
' Does data exist in the clipboard?
If MyDataObject.Ge tDataPresent(Sy stem.Windows.Fo rms.DataFormats .Text) Then
' Data exists, get it into a string
Dim strBuffer As String = CType(MyDataObj ect.GetData _
(System.Windows .Forms.DataForm ats.StringForma t), String)
Console.WriteLi ne(New System.Text.Str ingBuilder( _
"The copied/pasted data is: ").Append(strBu ffer).ToString( ))
Else
' No data exists.
Console.WriteLi ne("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 MyBinaryDataObj ect As System.Windows. Forms.IDataObje ct = _
System.Windows. Forms.Clipboard .GetDataObject( )
' Diaplay the formats currently available in the clipboard
Dim strFormats() As String = MyBinaryDataObj ect.GetFormats( True)
Console.WriteLi ne("Supported formats for current clipboard data: ")
Dim i As Integer
For i = 0 To strFormats.GetU pperBound(0)
Dim formatString As System.Text.Str ingBuilder = New _
System.Text.Str ingBuilder("For mat ").Append(i.ToS tring())
Console.WriteLi ne(formatString .Append(strForm ats(i)))
Next
End Sub
=============== =============== =============== ====
"Keith" <an*******@disc ussions.microso ft.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.select all() - 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(B yVal sender As System.Object,
ByVal e As System.EventArg s) Handles Button1.Click
Clipboard.SetDa taObject(TextBo x1.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.