Previous | Index | Next 

[PRB] Deleting a Toolbar, ListView, or StatusBar control prevents the form from loading in Visual Studio designer

A few VB6 controls – namely, the Toolbar, the ListView, and the StatusBar controls - are rendered in VB.NET as a pair of controls on the migrated form: one control of the pair is defined in the control support library, the other is defined in System.Windows.Forms.dll.

For example, a VB6 Toolbar control named MyToolbar is rendered as a VB6Toolbar control named MyToolbar plus a System.Windows.Forms.Toolstrip control named MyToolbar_Control.
The MyToolbar control is actually a class that derives from System.Windows.Forms.Control, is just 1x1 pixels wide, and is invisible at runtime.

This arrangement is necessary to preserve the full code-level compatibility and, at the same time, to let developers modify properties in the designer. VB.NET code referencing the MyToolbar control actually references the MyToolbar VB6Toolbar, which in turn forwards all requests to the MyToolbar_Control. The developer can directly change toolbar appearance and behavior by setting the properties of the MyToolbar_Control object.

This mechanism works well, but causes problems if the developer deletes the toolbar – that is, the MyToolbar_Control – from the designer without also deleting the MyToolbar control. In such a case, a NullReference exception is thrown at design time, which prevents the form from being displayed in the designer.

The fix for this issue is simple: If you delete a Toolbar, ListView, or StatusBar control from a form at design-time, please ensure that you also delete the corresponding VB6*** control. This control is just 1x1 pixels wide, thus the easiest way to find and select it is using the dropdown list in the property grid window.

A similar problem can occur if you move a Toolbar, ListView, or StatusBar control into another container. In this case, you should ensure that the companion control is moved into the same container.

 

Previous | Index | Next