BUG: TextBox does not resize when you set the Anchor property before you set the Multiline property (814344)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • 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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET (2003).
  2. On the File menu, point to New, and then click Project.
  3. In Project Types, click to select a Visual C# .NET project or a Visual Basic .NET project.
  4. In Templates, click to select Windows Application.
  5. Name the project MultiLineApplication, and then click OK.
  6. 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 = "MultiLineTextBox"
            ' 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 = "txt";
    			// 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());
    		}
    	}
    }
  7. On the Debug menu, click Start.

    The behavior discussed in" Symptoms" section of this article occurs.

Modification Type:MajorLast Reviewed:2/1/2006
Keywords:kbvs2005swept kbvs2005doesnotapply KbUIDesign kbWindowsForms kblayout kbForms kbProperties kbBug KB814344 kbAudDeveloper