posts from 2004

Dispose Modal WinForm Dialogs

By Fons Sonnemans, 12-dec-2004

There is a difference in disposing Modal and Non-Modal forms. In a training I gave last week I noticed that even experienced developers didn't know that Modal Dialogs don't dispose automatically, Non-Modal do.

private void buttonShowNonModalForm ( object sender , System.EventArgs e){
   &nbspnew TestForm().Show();

privatevoidbuttonShowModalDialog(objectsender, System.EventArgs e){
   &nbspnew Form2().ShowDialog();

The solution to this problem is very simple by creating the Form instance within a using block. This will dispose the Form when it is closed.

private void buttonShowModalDialog ( object sender , System.EventArgs e){
   &nbspusing(TestForm f =new TestForm()){
   &nbsp   &nbspf.ShowDialog();

An alternative solution uses a try/finnaly. Personally I prefer the previous, it is easier to read and write.


Best CV ever!

By Fons Sonnemans, 13-nov-2004
Tags: Work


C# HandleWhiteSpace Add-In

By Fons Sonnemans, 23-sep-2004



The C# code editor in Visual Studio.NET 2003 does not handle whitespaces automatically like the VB.NET code editor does. This Add-In solves this problem by adding the 'Handle WhiteSpace' menu option to the Visual Studio.NET 2003 Tools menu. This option formats the C# code of the active code editor. This includes:

  • Space before:  method declaration parentheses, method call parentheses, statement parentheses, braces and brackets
  • Space after: comma and semicolon
  • Space around: operators
  • Double space


Screen shot: Handle WhiteSpace menu option

After you have selected the menu option the C# source code is formatted with correct whitespaces.

Screen shot: Reformatted code


Writing clean C# code has become easier with this Add-In. I hope you enjoy using it.

I thank Heindirk de Laat for providing me the code for the most difficult part of the program. I only added some extra regular expressions and transformed it into an Add-In.

Any suggestions and feedback for improving this Add-In is most welcome. Send your suggestions and feedback to


DualList Drag & Drop Component

By Fons Sonnemans, 16-sep-2004


I have written an article two years ago with the title 'WinForm DualList Component'. In this article I mentioned the desire to extend the DualList component with Drag & Drop support. Finally it's done. Not by extending the original DualList component but by creating an new DualListDragDrop component (reason: cohesion).

Programming Drag & Drop (D&D) between listboxes is quite difficult. It requires at least 60 lines of code for every two listboxes. Therefore not many application support D&D. This component eliminates need of writing the code. You only have to set properties on it. Making it easy to support D&D in your applications.

DualListDragDrop Component

The DualListDragDrop component is a component which can be dropped in the 'component tray' of a windows Form. You therefore first have to add it to the Toolbox of Visual Studio.NET. This can easily be done by dragging   ReflectionITWinFormComponents.dll assembly from an normal Windows Explorer and dropping it on the Toolbox. All controls and components from the assembly will be added to the Toolbox. You can create an separate Tab for it if you want.

For each D&D direction you must add DualListDragDrop component to you Form. In this example three. For each component you have to set the '(Name)', 'ListBoxFrom' and 'ListBoxTo' properties.


You can use the DualListDragDrop component to reorder the position of the items in a ListBox by selecting the same 'From' and 'To' ListBox.

Action property

You can choose from three values for the Action property: Move, Copy and MoveAndCopy. The MoveAndCopy will normally move an item. You can copy the item by pressing the Ctrlkey while initiating the D&D operation.

DropIndicator property

The DropIndicator can be set to 'True' which means you will get a red dotted line indicating where the item will be placed when you drop the item. It supports scrolling the listbox up and down when you move your mouse over the first or last visible item. The item will be added to the bottom of the list when the property is set to 'False'. The color of the line can be selected using the IndicatorColor property.


The DualList and DualListDragDrop components are easy solutions for difficult features. It takes care of all logic needed to move and or copy items from one listbox to another. Use them in your own applications, they are free.

Hopefully this article will encourage more people to make use of the component architecture in their own applications.

Any suggestions and feedback for improving this article is most welcome. Send your suggestions and feedback to

License Information

The ReflectionITWinFormComponents assembly is free for use in commercial or private applications. However, you may only redistribute this in its compiled form (modified or unmodified), you may not redistribute the source or modified source. When using it, please include the line "ReflectionITWinFormComponents - Copyright Reflection IT -" reference in either the about or in the documentation. This will help me out and allow me to continue to provide you with free controls.


ToolboxBitmap workaround

By Fons Sonnemans, 03-sep-2004

I have found a solution for a problem which I had for a long time. I was unable to set the ToolboxBitmap attribute for a component using the (type, string) constructor. I found the solution for this problem (using an internal ResFinder class) on This site has also some other Windows Forms Tips and Tricks. Great!


New layout

By Fons Sonnemans, 30-aug-2004

I have changed the layout of my website this weekend. A friend of my helped me with the design, thanks Loek

I'm not really finished. I still have to translate some pages to Dutch. I also want to add 'comments' to the Blog. Hope to do this soon.

Tags: Work


Visual C# 2005 Express Edition Beta is great

By Fons Sonnemans, 14-jul-2004

I'm testing Visual C# 2005 Express Edition Beta and I really like it. It has all of the features which I need to build Windows Forms applications. The Editor has also all new IntelliSense, Refactoring and Code Snippets features. They work great and really can boost productivity.

I have tested it on a PC with only 256Mb of ram. This is for the beta not enough. You need at least 512Mb.

I'm using the Online MSDN Help, it works OK. The looks are good but I find it difficult to get to the 'overview' of a class.

For professional development I would advise to use Visual Studio. For hobby work use the Express versions.


Second day

By Fons Sonnemans, 01-jul-2004

After a disappointing soccer match yerterday I’m here to review the second day.

What disappoints me is that there are no sessions about Longhorn, WinFS, Xaml or Visual Studio Orca. I guess it is still so far away that it is not interesting to tell something about it. Still it is a pity. There should be new things to show after the PDC.

The overall quality of the sessions is OK, nothing special.

Tonight is the TechEd party, hope it will rock.

Tags: TechEd


First Day

By Fons Sonnemans, 30-jun-2004

This is my second day at TechEd. Yesterday was a good day. The Keynote started with a demo by a blind person (sorry I forgot his name). He demonstrated how difficult it is to surf the internet when you are blind and what we ‘developers’ should do to help him. The drum’s where very nice. It is funny to hear 6000 nerds drum. For the rest the keynote was boring.

I went to a very nice session WIN320 IIS and ASP.NET security. Not overwhelming but nice. My next session on DAT313 SQL Server 2005 Data Transformation Services was also nice. DTS has been greatly improved (at last).

The last two sessions did not really satisfy me. This could be my own fault. I was tired so I couldn’t concentrate very well.

I went to eat with my good friend Paul and some of his colleagues, Thai always good.

Today I’m going to a XP programming, InfoPath, WSE SQL 2005 session. Hope to enjoy myself. In the evening there is a big country party where we will watch the football game Portugal-The Netherlands. Hope we will win but once again I’m not very optimistic.

Tags: TechEd


TechEd Bloggers Europe

By Fons Sonnemans, 28-jun-2004
Tags: TechEd



All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors. The content on this site is licensed under a Creative Commons Attribution By license.