Microsoft KB Archive/814352

= 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 =

Article ID: 814352

Article Last Modified on 5/11/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * 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 &quot;Symptoms&quot; 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 &quot;Applies to&quot; section.



Steps to Reproduce the Behavior
 Create a new Windows application by using Microsoft Visual Basic .NET or Microsoft Visual C# .NET.

By default, Form1 is created. From the toolbox, drag a TextBox control onto Form1.  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 = &quot;&quot; Visual C# .NET Code this.Text = &quot;&quot;; Microsoft Visual J# .NET Code this.set_Text(&quot;&quot;);  On the Debug menu, click Start to run the application.

The TextBox control is not rendered correctly.

