Microsoft KB Archive/316171

= FIX: All controls on a Windows Form disappear if you remove the reference to one control from the project in Visual Basic .NET 2002 =

Article ID: 316171

Article Last Modified on 1/25/2006

-

APPLIES TO


 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q316171



SYMPTOMS
When you add several references to ActiveX controls in a Microsoft Windows Forms application that you created by using Microsoft Visual Basic .NET, and then you remove one of the references from the project, all of the controls on the form disappear.



RESOLUTION
To recover the controls that you lost when you removed the references, you must modify the Windows Form Designer-generated code as follows:  Open the Code window for Form1. Expand the &quot;Windows Form Designer generated code&quot; region.  Locate each of the following lines of code in the call to the IntializeComponent method, and then comment out each line: Friend WithEvents AxStatusBar1 As AxMSComctlLib.AxStatusBar Me.AxStatusBar1 = New AxMSComctlLib.AxStatusBar CType(Me.AxStatusBar1, System.ComponentModel.ISupportInitialize).BeginInit Me.AxStatusBar1.Dock = System.Windows.Forms.DockStyle.Bottom Me.AxStatusBar1.Location = New System.Drawing.Point(0, 357) Me.AxStatusBar1.Name = &quot;AxStatusBar1&quot; Me.AxStatusBar1.OcxState = CType(resources.GetObject(&quot;AxStatusBar1.OcxState&quot;),System.Windows.Forms.AxHost.State) Me.AxStatusBar1.Size = New System.Drawing.Size(424, 25) Me.AxStatusBar1.TabIndex = 1 CType(Me.AxStatusBar1,System.ComponentModel.ISupportInitialize).EndInit Note These lines of code do not appear sequentially in Microsoft Visual Studio .NET.   Modify the following code in the InitalizeComponent method from Me.Controls.AddRange(New System.Windows.Forms.Control {Me.TextBox1, Me.AxStatusBar1, Me.Button1}) to: Me.Controls.AddRange(New System.Windows.Forms.Control {Me.TextBox1, Me.Button1}) 

Note These steps are based on the sample from the &quot;More Information&quot; section. Therefore, this sample code may differ from the code in your project, depending on the controls that you use.



STATUS
This bug was corrected in Microsoft Visual Basic .NET 2003.



Steps to reproduce the problem

 * 1) Start Microsoft Visual Studio .NET.
 * 2) Create a new Windows Application project in Visual Basic .NET.
 * 3) Drag a Button control and a TextBox control from the toolbox to the form.
 * 4) In the Toolbox window, right-click the General tab, and then click Customize Toolbox.
 * 5) On the COM Components tab, click to select the Microsoft StatusBar Control 6.0 (SP4) check box from the Mscomctl.ocx file, and then click OK. Note that this control is included with Microsoft Visual Basic 6.0.
 * 6) Drag an instance of the StatusBar control from the toolbox to the form.
 * 7) Save the changes to your project, and then close the Designer window.
 * 8) In the Solution Explorer window, right-click AxMSComctlLib, and then click Remove to delete this reference. Similarly, right-click MSComctlLib, and then click Remove to delete this reference.
 * 9) In the Solution Explorer window, double-click Form1.vb to open the Designer window. Notice that all of the controls are missing, not just the controls that are missing dependencies.

Keywords: kbfix kbctrl kbvs2005swept kbvs2005doesnotapply KB316171

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.