Modeless forms in add-ins

Basically you could use three kind of forms in your add-ins:

  • Modal forms: these are regular forms that are shown modally and block the UI until you dismiss them. For example, the Options window of Visual Studio.
  • Modeless forms: there are regular forms that are shown non-modally. For example, the Find dialog of the old VB6. AFAIK, VS.NET doesn’t use modeless forms at all.
  • Toolwindows: these are special windows that can be docked to edges of the IDE. For example, the Solution Explorer, etc.

It happens that modeless forms are tricky: they had some problems in VB6 (like not being minimized along with the IDE) and if I remember correctly they were unable to get the focus (or keyboard input, not sure) in Visual Studio .NET, so using toolwindows is almost mandatory in VS.NET. But my MZ-Tools add-in for VB6/VB5/VBA used modeless forms for some features, using a hack to be minimized with the IDE rather than staying on the screen. The hack involved some call to the SetParent Windows API and some change in the window style. It seemed to work OK, but this month I discovered by chance that when running on Windows Vista with Aero and transparency activated, the modeless windows appear without border at all! The problem seems to be the SetParent call but I have been unabled to fix it, so I have changed all modeless forms to toolwindows (the fix will be available next month). Curiously the only modeless form that I use in the version of MZ-Tools for VS.NET (a progress form for some operations) appears correctly with border using a similar hack. But the bottom line is that modeless forms should be avoided in add-ins: it is much better to use toolwindows.