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



The information in this article applies to:

  • Microsoft Visual Basic .NET (2002)

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:
  1. Open the Code window for Form1.
  2. Expand the "Windows Form Designer generated code" region.
  3. 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 = "AxStatusBar1"
    Me.AxStatusBar1.OcxState = CType(resources.GetObject("AxStatusBar1.OcxState"),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.
  4. 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 "More Information" 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.

MORE INFORMATION

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.

Modification Type:MinorLast Reviewed:1/25/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbfix kbCtrl KB316171