2

I wanted to add a DoubleClick handler to an item in a ListBox (assume it is called ListBox), but I could not get it to appear using the Designer view.
I.E., double-clicking on the ListBox, I would only ever get ListBox_SelectedIndexChanged handlers wired up for me. (My list-box items are programmatically assigned, so there were no items in the Design view to click on -- is that an issue?)

I did work around this by coding up the handler myself (based on C# Listbox Item Double Click Event) but that took further research, since I had no idea that instead of looking for a MouseEventHandler in System, I had to drill down to System.Windows.Forms.. How annoying.

I.E., this.ListBox.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.ListBox_MouseDoubleClick);

So, is it possible to auto-generate a MouseDoubleClick event in the Design view?
Or do they have to be wired up by hand?

Not that I'm lazy, or anything. Other than using Visual Studio, I mean......

Community
  • 1
  • 1
Michael Paulukonis
  • 9,020
  • 5
  • 48
  • 68
  • How about the Events view in the Properties tool window (a yellow lightning icon)? You can doubleclick an empty field next to the event name, and the event handler will be auto-generated for you. (If you were not aware of this approach, I can repost it as an answer) – Yuriy Guts Mar 01 '12 at 21:49
  • I was not aware of this approach. Please repost it as an answer. doh! – Michael Paulukonis Mar 01 '12 at 21:51
  • Benefit of hindsight, why would I think that System.Windows.Forms would not have been the repository of methods for Windows Forms events? – Michael Paulukonis Mar 10 '14 at 15:39

1 Answers1

5

You can use the Events view in the Properties tool window to generate a handler for almost every event (some generic event handlers are not supported, as I remember). To auto-generate an event handler, double-click the empty field next to the event name.

For your case with ListBox.MouseDoubleClick, here's how to do it:

Using Events view to generate event handlers

Yuriy Guts
  • 2,180
  • 1
  • 14
  • 18
  • 1
    Exactly what I was looking for! After all these years, I think I need to hit up a "Visual Studio for Dummies" book, and look at all of the pictures VERY. CAREFULLY. – Michael Paulukonis Mar 01 '12 at 22:07
  • 1
    Yeah, I had exactly the same feeling when I discovered the Document Outline window after years of arranging containers/subcontainers using the mouse on the design surface :) – Yuriy Guts Mar 01 '12 at 22:10