2

I'm in VS IDE and when I double click a panel, it generates a paint event instead of a click event. I've tried other controls and they work fine.

Also, this just started happening today. I know that I can go to properties/events and double click the "click" field and it will produce the desired result, but it's a pain in the butt.

forgot to say... I'm using VS 2015

any help appreciated.

jumper
  • 91
  • 1
  • 15
  • I think you mean it creates a paint event handler. It is just the default for that control since a click event would be used far less often on a container control – Ňɏssa Pøngjǣrdenlarp Feb 03 '16 at 19:51
  • Yes, that is what I meant. Thanks for the answer. I didn't know that. Guess I've never tried to double click a panel before . If that's the default behavior, that's fine. Put what you posted in an answer and I will mark it the accepted solution. – jumper Feb 03 '16 at 19:54
  • I just explained why no click variation is the default - I have no idea why they chose the paint event since I didnt write it. (But if I had.....) – Ňɏssa Pøngjǣrdenlarp Feb 03 '16 at 19:58

1 Answers1

0

DefaultEventAttribute is used to specify the default event for a component. The docs for Panel (and presumably the other WinForms components) don't seem to show the value for the default event attribute, but if you look at the reference source (or decompile it yourself), you can see the value there:

[
ComVisible(true),
ClassInterface(ClassInterfaceType.AutoDispatch),
DefaultProperty("BorderStyle"),
DefaultEvent("Paint"),
Docking(DockingBehavior.Ask),
Designer("System.Windows.Forms.Design.PanelDesigner, " + AssemblyRef.SystemDesign),
SRDescription(SR.DescriptionPanel)
]
public class Panel : ScrollableControl {

I suppose the designers for each component pick the most frequently used event as the default, otherwise the base Control class defines a default of Click:

[
ComVisible(true),
ClassInterface(ClassInterfaceType.AutoDispatch),
DefaultProperty("Text"),
DefaultEvent("Click"),
Designer("System.Windows.Forms.Design.ControlDesigner, " + AssemblyRef.SystemDesign),
DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + AssemblyRef.SystemDesign, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + AssemblyRef.SystemDesign),
ToolboxItemFilter("System.Windows.Forms")
]
public partial class Control :
Mark
  • 8,140
  • 1
  • 14
  • 29
  • Thanks for pointing this out. I think I might use something in place of a panel. Or, I will just use the properties/events to add a click event to a panel. Thanks a bunch – jumper Feb 03 '16 at 23:43
  • The panel **has** a click event (and DoubleClick, MouseClick and MouseDoubleClick) none of them are the *Default* event (the one created when you dbl click in the designer) because it is a container control - meant to hold/group other things not interact with the user. @jumper – Ňɏssa Pøngjǣrdenlarp Feb 03 '16 at 23:55