Microsoft KB Archive/814351

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

Article ID: 814351

Article Last Modified on 11/14/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * 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
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * 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.



Steps to Reproduce the Behavior
 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. From the toolbox, drag a TextBox control onto Form1. In the design plane, right-click TextBox, and then click to select Properties. In the Properties window, set the Multiline property of the TextBox control to true. From the toolbox, drag a Button control onto Form1. Double-click Button Control to open the code view for the Button1_Click event.</li>  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 & &quot;BorderStyle = FixedSingle &quot;) Console.WriteLine(&quot;ClientSize is &quot; & TextBox1.ClientSize.ToString) Console.WriteLine(&quot;Size is &quot; & TextBox1.Size.ToString)

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

' Set BorderStyle to Fixed3D and print ClientSize and Size TextBox1.BorderStyle = BorderStyle.Fixed3D Console.WriteLine(vbCrLf & &quot;BorderStyle = Fixed3D &quot;) Console.WriteLine(&quot;ClientSize is &quot; & TextBox1.ClientSize.ToString) Console.WriteLine(&quot;Size is &quot; & 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( &quot;\nBorderStyle = FixedSingle &quot;); Console.WriteLine(&quot;ClientSize is &quot; + textBox1.ClientSize.ToString); Console.WriteLine(&quot;Size is &quot; + textBox1.Size.ToString);

// Set BorderStyle to None and print ClientSize and Size textBox1.BorderStyle = BorderStyle.None; Console.WriteLine( &quot;\nBorderStyle = None&quot;); Console.WriteLine(&quot;ClientSize is &quot; + textBox1.ClientSize.ToString); Console.WriteLine(&quot;Size is &quot; + textBox1.Size.ToString);

// Set BorderStyle to Fixed3D and print ClientSize and Size textBox1.BorderStyle = BorderStyle.Fixed3D; Console.WriteLine( &quot;\nBorderStyle = Fixed3D &quot;); Console.WriteLine(&quot;ClientSize is &quot; + textBox1.ClientSize.ToString); Console.WriteLine(&quot;Size is &quot; + textBox1.Size.ToString); </li> On the Debug menu, click Start.</li> On the View menu, point to Other Windows, and then click Output.</li> Click Button Control.

The ClientSize for various BorderStyle settings is displayed in the Output window.</li></ol>

<div class="references_section">