By adding a right click to a custom text field element in Visual Studio Designer?

I have a custom text field control, and when I double-click it adds the Text_Changed listen Text_Changed to the code that I can populate.

How can I add it to add the Right_Click listening Right_Click or the Left_Click listening method or the Double_Click listening Double_Click ?

+4
source share
2 answers

In Visual Studio, all your events are accessible by clicking the lightning bolt (Events) icon at the top of the Properties window.

Double-click the event name to create a new handler, or select an existing handler from the drop-down list.

+2
source

Right-click the text box and open the properties window. In the properties, click events (as shown in the figure below) and double-click the MouseDown event.

enter image description here

This will create a method. Then enter the following code:

 private void TextBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { // do something } } 

For the left click, you can use the same method or add the MouceClick event, which fires only when the left mouse button is clicked.

If you need to change this ContextMenu , then highlight this: Add ContextMenu to the TextBox

+3
source

All Articles