The text in right-aligned label controls is not right-aligned when the TextAlign property is set to MiddleRight (873197)
The information in this article applies to:
- Microsoft Visual Studio .NET (2003), Professional Edition
- Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2003), Academic Edition
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2002), Academic Edition
SYMPTOMSWhen you vertically align label controls and set the TextAlign property of the label controls to MiddleRight, the text in all the label controls may not be right-aligned.CAUSEThe Microsoft .NET Framework uses the Microsoft Windows GDI+ version instead of the GDI version. A GDI+ text layout is resolution independent. The text in a Windows form uses GDI+. Therefore, the text is not right-aligned in the label controls on Windows forms.RESOLUTIONTo resolve this problem, add a newline character or change the properties of the label controls. To add a newline character, follow these steps: - Start Microsoft Visual Studio .NET.
- On the File menu, point to Open, and then click Project.
- Locate the project, and then click Open.
- On the View menu, click Solution Explorer.
- In Solution Explorer, expand Project (where Project is the name of the project that you created).
- Right-click the Form1.cs file or the Form1.vb file, and then click View Code.
Note If you are using Microsoft Visual C# .NET, the file is a Form1.cs file. If you are using Microsoft Visual Basic .NET, the file is a Form1.vb file. - For Visual Basic .NET, locate the following code:
Me.Label3.Text = "!!!!!!!!" Replace the previous code with the following code:Me.Label3.Text = "!!!!!!!!" + vbCrLf For Visual C# .NET, locate the following code:this.label3.Text = "!!!!!!!!"; Replace the previous code with one of the following code samples:this.label3.Text="!!!!!!!!" + "\n"; this.label3.Text="!!!!!!!!" + "\r"; - On the Build menu, click Build Solution.
- On the Debug menu, click Start.
Note All the text in the label controls may be right-aligned.
To change the properties of the label controls, follow these steps: - Start Visual Studio .NET.
- On the File menu, point to Open, and then click Project.
- Locate the project, and then click Open.
- On the View menu, click Solution Explorer.
- In Solution Explorer, expand Project (where Project is the name of the project that you created).
- Right-click the Form1.cs file or the Form1.vb file, and then click View Designer.
- In design view for the Form1.cs file or the Form1.vb file, right-click the label control that you want to change, and then click Properties.
- In the Properties window, set the TextAlign property to MiddleLeft, and then set the RightToLeft property to Yes.
- On the Build menu, click Build Solution.
- On the Debug menu, click Start.
Note All the text in the label controls may be right-aligned.
WORKAROUNDTo work around this problem, use text box controls instead of label controls. You can also create a control that does not use GDI+. REFERENCESFor more information, visit the following MSDN Web site:
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
307208
Why text appears different when drawn with GDIPlus versus GDI
Modification Type: | Major | Last Reviewed: | 8/10/2004 |
---|
Keywords: | kbForms kbFont kbGDIPlus kbtshoot kbprb KB873197 kbAudDeveloper |
---|
|