Microsoft KB Archive/814344

= BUG: TextBox does not resize when you set the Anchor property before you set the Multiline property =

Article ID: 814344

Article Last Modified on 2/1/2006

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Academic Edition

-



SYMPTOMS
When you set the Multiline property of the TextBox control to True after you set the Anchor property, the TextBox may not resize to the size specified in the Size property of the TextBox. However, the TextBox enables you to enter multiple lines of text.



WORKAROUND
To work around this bug, use one of the following methods:   Set the Anchor property after you set the Multiline property, as in the following code:

Visual Basic .NET Code 'Setting Multiline property txtBox.Multiline = True ' Setting Anchor property txtBox.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Visual C# .NET Code // Setting Multiline property txtBox.Multiline = true; // Setting Anchor property txtBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;   Set the Size property of the TextBox after you set the Multiline property, as in the following code:

Visual Basic .NET Code ' Setting Anchor Property txtBox.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right ' Setting Multiline Property txtBox.Multiline = true ' Setting the size of the TextBox txtBox.Size = new System.Drawing.Size(100, 100) Visual C# .NET Code // Setting Anchor Property txtBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; // Setting Multiline Property txtBox.Multiline = true; // Setting the size of the TextBox txtBox.Size = new System.Drawing.Size(100, 100); 



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Start Microsoft Visual Studio .NET (2003). On the File menu, point to New, and then click Project. In Project Types, click to select a Visual C# .NET project or a Visual Basic .NET project.</li> In Templates, click to select Windows Application.</li> Name the project MultiLineApplication, and then click OK.</li>  Replace the existing code with the following code:

Visual Basic .NET Code Option Strict On

Imports System.Windows.Forms Imports System.Drawing Imports System

Class MultilineTextBoxForm : Inherits Form

' Constructor Sub New Dim txtBox As TextBox = New System.Windows.Forms.TextBox txtBox.Visible = True txtBox.Location = New System.Drawing.Point(8, 8) txtBox.Size = New System.Drawing.Size(100, 100) txtBox.Name = &quot;MultiLineTextBox&quot; ' With this order the TextBox may be resized txtBox.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right txtBox.Multiline = True ClientSize = New System.Drawing.Size(176, 176) Controls.Add(txtBox) End Sub

Shared Sub Main Application.Run(New MultilineTextBoxForm) End Sub End Class Visual C# .NET Code using System.Windows.Forms; using System.Drawing; using System;

namespace MultilineApplication {   public class MultilineTextBoxForm : Form {       // Constructor public MultilineTextBoxForm {           TextBox txtBox = new System.Windows.Forms.TextBox; txtBox.Visible = true; txtBox.Location = new System.Drawing.Point(8, 8); txtBox.Size = new System.Drawing.Size(100, 100); txtBox.Name = &quot;txt&quot;; // With this order the TextBox may be resized; txtBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; txtBox.Multiline = true; ClientSize = new System.Drawing.Size(176, 176); Controls.Add(txtBox); }

// Main method static void Main(String[] args) {           Application.Run(new MultilineTextBoxForm); }   } } </li> On the Debug menu, click Start.

The behavior discussed in&quot; Symptoms&quot; section of this article occurs.</li></ol>

Keywords: kbbug kbwindowsforms kbuidesign kbproperties kbforms kblayout kbvs2005swept kbvs2005doesnotapply KB814344

-

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

© Microsoft Corporation. All rights reserved.