Microsoft KB Archive/937215

= The text of a node may be truncated when you programmatically set the Font property of the node to the Bold value in a Windows Forms-based application that uses the .NET Framework 2.0 =

Article ID: 937215

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft .NET Framework 2.0

-



SYMPTOMS
Consider the following scenario. In a Microsoft Windows Forms-based application that uses the Microsoft .NET Framework 2.0, you create a node for a TreeView control. Then, you programmatically set the Font property of the node to the Bold value. In this scenario, the text of the node may be truncated.



WORKAROUND
To work around this problem, add an empty string to the text after you programmatically set the Font property of the node to the Bold value. To add an empty string, add the following code at the end of the button1_Click_1 event. treeView1.Nodes[0].Text += string.Empty; For example, locate the following code. private void button1_Click(object sender, EventArgs e)       { treeView1.Nodes[0].NodeFont = new System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 12F, System.Drawing.FontStyle.Bold); } Replace this code by using the following code. private void button1_Click(object sender, EventArgs e)       { treeView1.Nodes[0].NodeFont = new System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 12F, System.Drawing.FontStyle.Bold); treeView1.Nodes[0].Text += string.Empty; }



Steps to reproduce the problem
 Start Microsoft Visual Studio 2005. On the File menu, click New Project. In the New Project dialog box, click Visual C# under Project Types, and then click Windows Application under Visual Studio Installed Templates. In the Name box, type, and then click OK. On the View menu, click Toolbox. In the Toolbox, click the TreeView control under Common Controls, and then add a TreeView control to the form. In the Toolbox, click the Button control under Common Controls, and then add a Button control to the form.</li> In the Properties window, click TreeView1 System.Windows.Forms.TreeView.</li> In the TreeView1 properties, click Nodes, and then click the ellipsis button (...) to open the TreeNode Editor.</li> In the TreeNode Editor, click Add Root.</li> In the TreeNode Editor, click Text under Appearance, type a long sentence, and then click OK.</li> In the Properties window, click button1 System.Windows.Forms.Button.</li> In the button1 event properties, double-click Click under Action.

Note The Form1.cs page opens.</li>  On the Form1.cs page, locate the following code. private void button1_Click_1(object sender, EventArgs e)       { } </li>  Replace this code by using the following code. private void button1_Click(object sender, EventArgs e)       { treeView1.Nodes[0].NodeFont = new System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 12F, System.Drawing.FontStyle.Bold); } </li> On the Debug menu, click Start Debugging. This problem occurs when you click button1.</li></ol>

Keywords: kbtshoot kbprb KB937215

-

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

© Microsoft Corporation. All rights reserved.