473,395 Members | 1,521 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,395 software developers and data experts.

Cut, Copy, Paste code

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
Mar 20 '08 #1
11 9605
John,

You are probably at the moment the guy who asks the most in these
newsgroups, no problem, however by just copying in your problem in MSDN you
get all the answers you want about that.

When you set your search string than use the trick to set as
well -blogs -forums to prevent that you get all kind of rubish.

http://msdn2.microsoft.com/en-us/default.aspx

When you can not get your answer there, or it is not clear to you, then
place your question here.

Cor

"John" <in**@nospam.infovis.co.ukschreef in bericht
news:Oq**************@TK2MSFTNGP06.phx.gbl...
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
Mar 20 '08 #2
What are you trying to cut, copy, and paste? The data displayed on the whole
form? Text in a textbox?

RobinS.
GoldMail.com

"John" <in**@nospam.infovis.co.ukwrote in message
news:Oq**************@TK2MSFTNGP06.phx.gbl...
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
Mar 20 '08 #3
On Mar 20, 4:22 am, "John" <i...@nospam.infovis.co.ukwrote:
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
John,
For your purpose, there's a built-in template does this. Insert
MenuStrip control. Right click -Insert Standard Items.

Now the items that you're looking for are created, now just you need
to write codes for each item.
Mar 20 '08 #4
Text in fields.

Thanks

Regards

"RobinS" <ro****@imnottelling.comwrote in message
news:hI******************************@comcast.com. ..
What are you trying to cut, copy, and paste? The data displayed on the
whole form? Text in a textbox?

RobinS.
GoldMail.com

"John" <in**@nospam.infovis.co.ukwrote in message
news:Oq**************@TK2MSFTNGP06.phx.gbl...
>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

Mar 20 '08 #5
I only need code for actual Copy, Cut and paste operation. I already have
menus (infragistics) setup.

Thanks

Regards

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:e5**********************************@a23g2000 hsc.googlegroups.com...
On Mar 20, 4:22 am, "John" <i...@nospam.infovis.co.ukwrote:
>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

John,
For your purpose, there's a built-in template does this. Insert
MenuStrip control. Right click -Insert Standard Items.

Now the items that you're looking for are created, now just you need
to write codes for each item.

Mar 20 '08 #6
Add a context menu to the text control
Add menu items i.e. copy/cut/paste.
Add commands to the menu items

Delete
My.Computer.Clipboard.SetText(TextBox1.SelectedTex t)
TextBox1.Text = TextBox1.Text.Replace(TextBox1.SelectedText, "")

SelectAll
TextBox1.SelectAll()

Paste
TextBox1.Text = My.Computer.Clipboard.GetText

Undo
TextBox1.Undo()

Cut
My.Computer.Clipboard.SetText(TextBox1.Text)
TextBox1.Text = ""

Also make sure to enable/disable menu items kind like the following
Private Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles TextBox1.TextChanged

PasteToolStripMenuItem.Enabled = My.Computer.Clipboard.ContainsText
DeleteToolStripMenuItem.Enabled = TextBox1.SelectionLength 0
CutToolStripMenuItem.Enabled = DeleteToolStripMenuItem.Enabled
CopyToolStripMenuItem.Enabled = DeleteToolStripMenuItem.Enabled
UndoToolStripMenuItem.Enabled = TextBox1.CanUndo
End Sub

Your context menu will replace the normal menu say on a textbox.

Hope this helps,
Kevin

"John" <in**@nospam.infovis.co.ukwrote in message
news:Oq**************@TK2MSFTNGP06.phx.gbl...
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

Mar 20 '08 #7
Hi Kevin

Many thanks. This is very useful.

Regards

"ke*************@state.or.us" <Ke***************@state.or.uswrote in
message news:%2****************@TK2MSFTNGP06.phx.gbl...
Add a context menu to the text control
Add menu items i.e. copy/cut/paste.
Add commands to the menu items

Delete
My.Computer.Clipboard.SetText(TextBox1.SelectedTex t)
TextBox1.Text = TextBox1.Text.Replace(TextBox1.SelectedText, "")

SelectAll
TextBox1.SelectAll()

Paste
TextBox1.Text = My.Computer.Clipboard.GetText

Undo
TextBox1.Undo()

Cut
My.Computer.Clipboard.SetText(TextBox1.Text)
TextBox1.Text = ""

Also make sure to enable/disable menu items kind like the following
Private Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles TextBox1.TextChanged

PasteToolStripMenuItem.Enabled = My.Computer.Clipboard.ContainsText
DeleteToolStripMenuItem.Enabled = TextBox1.SelectionLength 0
CutToolStripMenuItem.Enabled = DeleteToolStripMenuItem.Enabled
CopyToolStripMenuItem.Enabled = DeleteToolStripMenuItem.Enabled
UndoToolStripMenuItem.Enabled = TextBox1.CanUndo
End Sub

Your context menu will replace the normal menu say on a textbox.

Hope this helps,
Kevin

"John" <in**@nospam.infovis.co.ukwrote in message
news:Oq**************@TK2MSFTNGP06.phx.gbl...
>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


Mar 20 '08 #8
"John" <in**@nospam.infovis.co.ukschrieb
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?
I wonder why you want to do something that you don't know how to do it.
I want to build an aircraft, but I don't know how to do, so I don't do
it. If I work in an aircraft building company and am instructed to build
an aircraft and don't know how to do it, I'd wonder if it is the right
job for me. You seem to work in such a company and ask the fellow
workers to do the work for you because you don't know how to do it - so,
what do you get paid for?
Armin

Mar 20 '08 #9
John wrote:
Hi Kevin

Many thanks. This is very useful.

Regards
Before you go implementing all of that, have you right clicked on a text box
before? There is already a context menu with all of that in there. Just
wondering why you are replacing a working wheel...
Mar 20 '08 #10
Steve this is fine but I need to implement these in the main menu on the
top.

Thanks

Regards

"Steve Gerrard" <my********@comcast.netwrote in message
news:Vq******************************@comcast.com. ..
John wrote:
>Hi Kevin

Many thanks. This is very useful.

Regards

Before you go implementing all of that, have you right clicked on a text
box before? There is already a context menu with all of that in there.
Just wondering why you are replacing a working wheel...


Mar 20 '08 #11
On Mar 20, 2:07*am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
John,
For your purpose, there's a built-in template does this. Insert
MenuStrip control. Right click -Insert Standard Items.

Now the items that you're looking for are created, now just you need
to write codes for each item.
Which doesn't help him (or me) that much. This is what I came up with
(most leeched from the MSDN example but hacked to work on any textbox
for example. For other controls add code as needed):

Private Function GetControl() As Control
Dim cControl As ContainerControl, aControl As Control

aControl = Me.ActiveControl

Do
If TypeOf aControl Is TextBox Then Exit Do
' Cast to ContainerControl to access next level
ActiveControl
cControl = CType(aControl, ContainerControl)
aControl = cControl.ActiveControl
Loop

If TypeOf aControl Is TextBox Then
GetControl = aControl
Else
GetControl = Nothing
End If

End Function

Private Sub Menu_Copy(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuCopy.Click, btnCopy.Click
Dim tControl As TextBox
' Ensure that text is selected in the text box.
tControl = CType(GetControl(), TextBox)
If tControl.SelectionLength 0 Then
' Copy the selected text to the Clipboard.
tControl.Copy()
End If
End Sub

Private Sub Menu_Cut(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuCut.Click, btnCut.Click
Dim tControl As TextBox
' Ensure that text is currently selected in the text box.
tControl = CType(GetControl(), TextBox)
If tControl.SelectedText <"" Then
' Cut the selected text in the control and paste it into
the Clipboard.
tControl.Cut()
End If
End Sub

Private Sub Menu_Paste(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPaste.Click, btnPaste.Click
Dim tControl As TextBox
' Determine if there is any text in the Clipboard to paste
into the text box.
tControl = CType(GetControl(), TextBox)
If Clipboard.GetDataObject().GetDataPresent(DataForma ts.Text)
= True Then
' Determine if any text is selected in the text box.
If tControl.SelectionLength 0 Then
' Ask user if they want to paste over currently
selected text.
If MessageBox.Show("Do you want to paste over current
selection?", _
"Cut Example", MessageBoxButtons.YesNo) =
DialogResult.No Then
' Move selection to the point after the current
selection and paste.
tControl.SelectionStart = tControl.SelectionStart
+ _
tControl.SelectionLength
End If
End If
' Paste current text in Clipboard into text box.
tControl.Paste()
End If
End Sub

Private Sub Menu_Undo(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuUndo.Click
Dim tControl As TextBox
tControl = CType(GetControl(), TextBox)
' Determine if last operation can be undone in text box.
If tControl.CanUndo = True Then
' Undo the last operation.
tControl.Undo()
' Clear the undo buffer to prevent last action from being
redone.
tControl.ClearUndo()
End If
End Sub
Jun 27 '08 #12

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

Similar topics

5
by: Stephen Russell | last post by:
I am getting frustrated! I have huge strings in making segments for a SP in SQL Server. Everything looks good but I want to copy and then past into ISQL as a test. this is my error: Line 1:...
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...
3
by: Rachel Suddeth | last post by:
This may not be the right forum, but it's a problem I chiefly come across when trying to post here. When I do a copy/paste from VS, the text always looks really weird (and even if I'm in an...
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...
5
by: Kaur | last post by:
Hi, I have been successful copying a vba code from one of your posts on how to copy and paste a record by declaring the desired fields that needs to be copied in form's declaration and creating two...
6
by: Ben R. | last post by:
Hi, I've got a vb.net winforms app. Out of the box, I can use Ctrl X, C and V as expected in controls like textboxes. I've got a menustrip, and if I click the link "Add standard items" which...
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...
7
kcdoell
by: kcdoell | last post by:
Good morning everyone: I created a form and set the default view as a continuous form. Basically the form is displaying records in which the user can add or edit new ones. The record source for...
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.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
0
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,...
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...

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.