Custom User Control in C#...Right Click Menu to Copy Text (Java Developer learning C#)

c#, user-controls, visual-studio-2008, winforms

Solution

Examine the `ContextMenu` control and the `ContextMenu` property of other controls. By assigning a ContextMenu control to the ContextMeny property of another control, you will have the right-click->popup menu wiring done for you. Then you only need to implement the click event of the different menu items in the context menu.

Then you can use the `Clipboard.SetText` (as suggested by BFree) to set the desired value to the clipboard.

Problem

I'm working on a custom user control that essentially displays a name value pair (name is on a black background, value on a white). I have my control displaying correctly, even showing up in Designer and on my build page. What I'd like to do from here is have the ability to right click on the user control and have a menu come up that has a "Copy Value" option, that when selected will copy the value in the "value" part of the user control to the clipboard. What is the best method of approach? I'm not sure where to start since most of the documentation on user controls I've found deals with displaying the control, not necessarily interacting with it. Additionally, since I'm still learning C#, I might have left out an important part of my problem in this question, so please point that out if it's the case. I'm using Visual Studio 2008 (if that matters).

Original source