473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Cut Copy Paste Undo

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
2 2655
* "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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: XmlAdoNewbie | last post by:
Hi All, I would like to put a method for copy, cut and paste into my application and this seems to be easy enough except that it's not working the way i would like it to, I thought someone might...
4
by: Legendary Pansy | last post by:
I was checking out the 101 C# Samples, specifically Windows Forms - Use the Clipboard. I took a look at the code for a while, and I understand what the program is doing with the cut, copy, pasting...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
2
by: Tomas | last post by:
Hi, I am a VB.NET newbie that would like to know the best practise when working with objects and undo user changes to objects properties. Problem The system allows the user to change...
17
by: Steve | last post by:
I'm trying to code cut, copy, and paste in vb 2005 so that when the user clicks on a toolbar button, the cut/copy/paste will work with whatever textbox the cursor is current located in (I have...
11
by: John | last post by:
Hi In a winform app I need to provide a menu with Cut, Copy and Paste options., What code do I use to accomplish cut, copy and paste features for fields on a winfrom? Thanks Regards
5
by: phill86 | last post by:
Hi I have a main form that holds records for scheduled meetings, date time location etc... in that form i have a sub form that has a list of equipment resources that you can assign to the meeting in...
8
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any help? Thanks.
6
by: xenocidecrash | last post by:
I am using: C#, .Net, Windows Forms I have created a derived class from the System.Windows.Forms.TextBox class that only allows hexadecimal characters to be entered, whether typed or pasted....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.