BUG: The controls on the form do not render correctly if you set the ControlBox property to False or set the Text property to an empty string in the form load event (814352)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition

SYMPTOMS

If you perform one of the following steps in the form load event, the controls on the form do not render correctly:
  • Set the Text property of the form to an empty string.

-or-

  • Set the ControlBox property of the form to False.

If you set the Text property or the ControlBox property in this way, the controls are not painted. You may not be able to see the controls correctly on the form. With multiple-document interface (MDI) forms, the parent form of a MDI application is not correctly painted. However, this behavior may not occur for MDI child forms.

CAUSE

This issue occurs when the Invalidate method invalidates a specific region of the control. The Invalidate method sends a paint message that paints the control. You invalidate the controls on the form if you set either of the properties as mentioned in the "Symptoms" section of this article. However, the Invalidate method is not called when these properties are set in the form load event.

WORKAROUND

To work around this issue, use one of the following methods:
  • Call the Refresh method of the form after the code in the Form1_Load event.

    This forces the controls to invalidate their client area, redraw themselves, and redraw any child controls.

-or-

  • Write the code in the constructor of the form.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new Windows application by using Microsoft Visual Basic .NET or Microsoft Visual C# .NET.

    By default, Form1 is created.
  2. From the toolbox, drag a TextBox control onto Form1.
  3. Add the following code in the Form1_Load event. To do this, double-click Form1 in the design view to open the code window. In the Form1_Load event, type the following code:

    Visual Basic .NET Code
    Me.Text = ""
    Visual C# .NET Code
    this.Text = "";
    Microsoft Visual J# .NET Code
    this.set_Text("");
  4. On the Debug menu, click Start to run the application.

    The TextBox control is not rendered correctly.

REFERENCES

For more information, visit the following Microsoft Web site:

Control.Invalidate Method ()
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsControlClassInvalidateTopic1.asp

Modification Type:MinorLast Reviewed:1/25/2006
Keywords:kbvs2005doesnotapply kbvs2005swept kbvs2002sp1sweep kbCtrl kbControl kbWindowsForms kbdraw kbbug KB814352 kbAudDeveloper