Did you know that you can use LINQPad to test your WinForms app while you're doing development, and easily ? I don't think that this is a feature that's widely used (and in fact, I don't think that the author himself thought of that idea! ::grins, hi Joe!::) while using LINQPad.
So, how do you do it ?
Right click in your query window and select Advanced Properties. On the Additional References tab select "Add" and then "Browse". Find the assembly that you wish to test. Also make sure you add any other necessary assemblies, and especially System.Windows.Forms.dll. You'll then want to switch to the Additional Namespace Imports tab and type in the Namespace of your assembly that you wish to test, so that you'll have IntelliSense.
* Important Note: Make sure you list your namespaces in the "most dependant ones last." i.e., start with System.Windows.Forms so that you'll get proper IntelliSense.
Now, with something similar to the following code (make sure to switch the language to C# Program and put this in the Main {} method):
using(MyFormThatIWantToTest myForm = new MyFormThatIWantToTest()) {
myForm.ShowInTaskbar = true;
myForm.ShowDialog();
}
It's important to set your form to show in the taskbar because if you open it as a Dialog without, it will be very easy for you to lose you form. The reason for opening it as a Dialog.. if you don't, the form will immediately close.
You can use this technique (I call it "LINQBugging") to test a lot of different scenarios and in some cases, save yourself a lot of time. Why does this save you time ? You can jump straight to your form/dialog without having to go through any unnecessary steps that you might otherwise if you launch your application directly, or from Visual Studio. I use this technique all the time. Couple this with Hawkeye to quickly prototype and test forms within your application and bypass the tedious navigation and security of your application to get there.
Also, make sure you open up your project in Visual Studio! You can make changes and recompile your application and then execute (something similar to the above code) your LINQPad "Query" again. One note, you need to close you form if you have it opened with LINQPad, otherwise the executable will become locked. After that, once you make changes to your source code and recompile, LINQPad will execute the new code the next time you run the "query".
There are a lot of other things that you can do with this technique.. testing libraries, writing test procedures, etc. Now that you know how to do this, what other tips and tricks do you have that I haven't thought of ?
* Note: Yes, you can have a lot of fun with applications that aren't your own.. a little Reflector, and a little LINQPad can go a long way. Don't abuse it. :)
Thanks for reading,
Matthew MacSuga