473,761 Members | 8,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.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.
Nov 20 '05 #1
2 2684
* "Keith" <an*******@disc ussions.microso ft.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.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?


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/RichTextBoxCont ext.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( 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.

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3075
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 be able to give me a bit of insight and for that I say Thank You in advance! this is what I have so far. private void CutText() {
4
21626
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 via the file menu events using the clipboard. However, what I don't get is how is the program able to produce a context menu in the textbox area. When right clicking, the context pops up and allows to cut/copy/paste/delete, etc.. But the thing is, I...
7
11638
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 is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
2
1973
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 properties of an object; the system then does some time consuming calculation and provide a solution to the user. If the user found the solution unsatisfactory, he/she could either continue making more changes or undo all changes done
17
5129
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 about 20 textboxes on the form). Also to ensure that the button can't get used if the cursor isn't in a textbox field. And to ensure the contents of the clipboard are "text" contents that have been cut/copied from one of the textboxes on the form. ...
11
9660
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
11153
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 the main form. I have two buttons in the sub form one for selecting and copying all the records and another for pasting the records this enables me to copy and paste the equipment resources from one scheduled meeting to another. The buttons are...
8
15441
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
6535
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. (pasting just strips out all non-hex characters). It works fine except for the fact that I can't undo after pasting into the box. I feel this must have something to do with the fact that I took over WindProc for the WM_PASTE message, but I'm not sure...
0
9522
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9336
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8770
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.