Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify Double-Click event for a Control in Visual Studio Designer

When you Double-Click on a Control in the Visual Studio Designer, you automatically subscribe to some event and an Event Handler is generated in the code behind file.

Double-Clicking on the following Controls subscribes to the corresponding event

  • UserControl - Loaded
  • Button - Click
  • TextBox - TextChanged
  • Grid - No event
    etc.

How is this specified, is it a Visual Studio setting? Can this be overrideen and how can you specify which event you want to link to Double-Click for e.g. a Custom Control?

Thanks

like image 244
Fredrik Hedblad Avatar asked Jan 11 '11 00:01

Fredrik Hedblad


1 Answers

There is a DefaultEventAttribute that controls can specify. The designer knows to read this attribute and uses it to determine which event to use as the default.

[DefaultEvent("DoubleClick")]
public class MyClass {

    public event EventHandler DoubleClick;

}

There is also a DefaultPropertyAttribute which is significantly less useful. It just determines the default property name to select in the property grid when the control is selected in the designer.

like image 114
Josh Avatar answered Oct 21 '22 01:10

Josh