Cut / Copy / Paste ????

G

Guest

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 don't see a context menu assigned to txtPaste in Visual Studio properties box. Even then, when I search for the cut/copy/paste code, I come up short. Nothing. What kind of magic is this? I know of the textbox.copy(), textbox.cut(), textbox.paste() functions for a textbox control box. But I don't see this being used at all

Even then, I tried viewing other sample codes to see if any code pops up screaming at me here I am. But no. Same thing. There's no site of the right click context menu with the cut/copy/paste selection. Am I missing something here? I want to get in on the secret invisible coding that allows cut/copy/paste

I was wondering if there exists a much quicker way to implement cut/copy/paste without going through the entire windows form's textboxes and manually creating each cut/copy/paste function. That sounds the stupid and hardway. There must be an easier way... Looks like the Using the Clipboard sample code does such thing (along with other code samples I've looked at), without showing a lot of coding for cut/copy/paste events

Help?
 
C

C# Learner

Legendary said:
[...]
But the thing is, I don't see a context menu assigned to txtPaste [...]

I think you're asking why text boxes provide a context-menu which allows
one to cut, copy and paste without any coding required.

Well, text boxes automatically provide a context-menu which allows the
user to undo, cut, copy, paste, delete and select all. When you use a
text box, you automatically get all this functionality with it.
 
G

Guest

Thanks for the reply C# Learner. You're right. It is automatically generated. Sweet, less coding for me. So I'll turn to my next problem: is there a quick way to do the richtextbox or do I have to manually code that in? When I placed the textbox, I can see it generated the context menu automatically. That's great. But when I put in the richtextbox, there's no context menu. Although the richtextbox doesn't have context menu, the functionality of cut/copy/paste exists from Ctrl+X, Ctrl+C, Ctrl+V

Is there a quick way to generate the context menu that the textbox has for richtextbox or do I have to emulate it and code in the context menu myself

Thanks.
 
C

C# Learner

Legendary said:
[...]
Is there a quick way to generate the context menu that the textbox has for richtextbox
or do I have to emulate it and code in the context menu myself?
[...]

Yeah, I believe you'll have to do it manually, with a RichTextBox.

You can use a ContextMenu component, assign the reference to
RichTextBox.ContextMenu, then respond to the ContextMenu click events,
calling RichTextBox.Cut, RichTextBox.Copy, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top