BUG: The ClientSize property of the TextBox control incorrectly includes the size of the borders if the BorderStyle property is set to BorderStyle.FixedSingle (814351)



The information in this article applies to:

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

SYMPTOMS

The ClientSize property either receives or sets the height and the width of the control client area. The client area is the periphery of the control. The client area does not include non-client elements such as scroll bars, borders, title bars, and menus. If the BorderStyle property of the TextBox control is set to BorderStyle.FixedSingle, the ClientSize property of the TextBox control incorrectly includes the size of the borders.

WORKAROUND

To work around this problem use one of the following methods:
  • Deduct the size of the TextBox control borders. TextBox returns the ClientSize property when the BorderStyle property of the TextBox control is set to BorderStyle.FixedSingle. The border size of a control depends on the display settings of your computer.

-or-

  • Use the RichTextBox control instead of TextBox control.

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. In Visual Studio .NET or Visual Studio 2005, create a new Windows application by using Microsoft Visual Basic 2005, Microsoft Visual Basic .NET, Microsoft Visual C# 2005, or Microsoft Visual C# .NET.

    By default, Form1 is created.
  2. From the toolbox, drag a TextBox control onto Form1.
  3. In the design plane, right-click TextBox, and then click to select Properties.
  4. In the Properties window, set the Multiline property of the TextBox control to true.
  5. From the toolbox, drag a Button control onto Form1.
  6. Double-click Button Control to open the code view for the Button1_Click event.
  7. Add the following code to the Button1_Click event:

    Visual Basic .NET or Visual Basic 2005 Code

       ' Set BorderStyle to FixedSingle and print ClientSize and Size		
       TextBox1.BorderStyle = BorderStyle.FixedSingle
       Console.WriteLine(vbCrLf & "BorderStyle = FixedSingle ")
       Console.WriteLine("ClientSize is " & TextBox1.ClientSize.ToString())
       Console.WriteLine("Size is " & TextBox1.Size.ToString())
    
       ' Set BorderStyle to None and print ClientSize and Size
       TextBox1.BorderStyle = BorderStyle.None
       Console.WriteLine(vbCrLf & "BorderStyle = None")
       Console.WriteLine("ClientSize is " & TextBox1.ClientSize.ToString())
       Console.WriteLine("Size is " & TextBox1.Size.ToString())
    
       ' Set BorderStyle to Fixed3D and print ClientSize and Size
       TextBox1.BorderStyle = BorderStyle.Fixed3D
       Console.WriteLine(vbCrLf & "BorderStyle = Fixed3D ")
       Console.WriteLine("ClientSize is " & TextBox1.ClientSize.ToString())
       Console.WriteLine("Size is " & TextBox1.Size.ToString())

    Visual C# .NET or Visual C# 2005 Code

       // Set BorderStyle to FixedSingle and print ClientSize and Size		
       textBox1.BorderStyle = BorderStyle.FixedSingle;
       Console.WriteLine( "\nBorderStyle = FixedSingle ");
       Console.WriteLine("ClientSize is " + textBox1.ClientSize.ToString());
       Console.WriteLine("Size is " + textBox1.Size.ToString());
    
       // Set BorderStyle to None and print ClientSize and Size
       textBox1.BorderStyle = BorderStyle.None;
       Console.WriteLine( "\nBorderStyle = None");
       Console.WriteLine("ClientSize is " + textBox1.ClientSize.ToString());
       Console.WriteLine("Size is " + textBox1.Size.ToString());
    
       // Set BorderStyle to Fixed3D and print ClientSize and Size
       textBox1.BorderStyle = BorderStyle.Fixed3D;
       Console.WriteLine( "\nBorderStyle = Fixed3D ");
       Console.WriteLine("ClientSize is " + textBox1.ClientSize.ToString());
       Console.WriteLine("Size is " + textBox1.Size.ToString());
  8. On the Debug menu, click Start.
  9. On the View menu, point to Other Windows, and then click Output.
  10. Click Button Control.

    The ClientSize for various BorderStyle settings is displayed in the Output window.

REFERENCES

For more information, visit the following Microsoft Web site:

Control.ClientSize Property
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclassclientsizetopic.asp

Modification Type:MajorLast Reviewed:1/21/2006
Keywords:kbvs2005applies kbvs2005swept kbvs2002sp1sweep kbWindowsForms kbControl kbCtrl kbbug KB814351 kbAudDeveloper