Archives / 2006 / December
  • How to Delete an WinForms Control Event Handler Quickly

    Recently a long-time user of Visual Studio looked over my shoulder when I deleted an event handler from my source code, and he said “uh, wait… how did you do that?”. If you are like him, not using the keyboard for this task, and would like to speed up things a bit, you may find this tip useful.

    Imagine you have an event handler in a file MyForm.cs, e.g.

    private void myButton_Click( object sender, EventArgs e )
       // ... some code ...

    Deleting only this method obviously results in a compiler error as there’s a line

    this.myButton.Click += new System.EventHandler( this.myButton_Click );

    in the file MyForm.Designer.cs that has to be deleted as well.

    To delete the event handler properly in Visual Studio 2005, using only the keyboard, perform the following steps:

    • In the MyForm.cs file, move the cursor on the name of the method file (i.e. myButton_Click) and press Shift-F12 (command Edit.FindAllReferences), which will bring you to the Find Symbols Results window.
    • press the Cursor Down key to move to the second line showing the occurrence of myButton_Click in the designer-generated code that connects the event with the handler method*
    • press Enter to jump to the MyForm.Designer.cs file
    • delete the current line by pressing Ctrl-Shift-L (command Edit.LineDelete)
    • jump back to the MyForm.cs by pressing Ctrl-Tab
    • and finally delete the code of the event handler method.

    The description of the steps may sound a bit complicated at first, but you’ll find that the actual keystrokes come naturally pretty soon.

    *) Note that this is only the case when the form was actually created in Visual Studio 2005 – keep your eyes open when working with forms in older projects that were started in Visual Studio .NET 200x.

  • Thank You!

    There’s a time for complaining about issues, and there’s a time for telling when things are great.

    I’m right in the middle of writing custom column and cell types for a DataGridView and I had a problem with adding a custom column to an existing grid – the DataGridView threw an exception in design mode, obviously a bug in my new code.

    It took me only a couple of minutes to

    • start a second instance of Visual Studio for debugging*
    • open the current solution a second time
    • open the designer for the dialog the DataGridView was on
    • add the custom column
    • watch the first Visual Studio instance point me to the source code location where the resulting exception was thrown
    • edit the code (after letting Visual Studio unwind the exception)
    • and continue with a now working custom column.

    Some of you out there may shrug their shoulders and ask “so what?”, but I must admit that even though I have used edit and continue for code running in Visual Studio before (when developing managed add-ins), I never cease to be freaking amazed! So to whoever contributed his/her part to making this work: Thank You!

    *) Project Properties – Debug – Start Action – Start external program – enter the full path of devenv.exe

  • WPF/E CTP - Nice, but...

    I just downloaded the WPF/E CTP bits (a good starting point for all things WPF/E is the new Dev Center). If you are a C# dev who has waited for the CTP as eagerly as I did, be prepared for a slight disappointment: right now you can only use Javascript, but no managed code – yet. Fortunately a blog post by Scott Guthrie gives a hint of things to come: “…We'll also be providing "WPF/E" integration with .NET managed code next year ”.

    Regarding the roadmap, the WPF/E FAQ says “Microsoft plans to deliver a customer-deployable release in the first half of 2007”, with Joe Stegman mentioning upcoming CPTs in this blog post: “Our next milestone is scheduled for February 2007 and the feature set for this is in development and mostly fixed. The milestone after that will be driven largely by customer feedback”.