Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Winforms: Spacing between text displayed within a control may change at runtime and design-time.
| Article ID | : | 954277 |
| Last Review | : | June 11, 2008 |
| Revision | : | 1.0 |
Source: Microsoft Support
Back to the top
RAPID PUBLISHING
RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
Back to the top
Action
Consider the following scenarios
1. You create a new Visual Basic Windows application in Visual Studio 2005 and uncheck the “Enable Application Framework†from the Project Properties->Application Page.
2. You upgrade a Visual Basic .NET 2003 project to Visual Basic 2005.
In these scenarios you add a Control or make changes to an existing control with the AutoSize property set to false and set its width so that it is just wide enough to encapsulate the text contained within the Control.
Â
Back to the top
Result
The spacing between words in the text contained within the control may change when you run the application. For example, this may cause text contained within a label control to be wrapped to the next line, truncating the text.
Back to the top
Cause
A new feature has been introduced in .NET Framework 2.0 where certain windows forms controls can render their text using either the GDI library or the newer GDI+ library. When the “Enable Application Framework†is unchecked or the project is upgraded from an earlier version of Visual Basic, the application-wide Application.SetCompatibleTextRenderingDefault is not set, so the Control.UseCompatibleTextRendering defaults to true for controls that support compatible text rendering. This makes them default to the GDI library and causes spacing between text to change for a control at design-time and at runtime.
Back to the top
Resolution
Â
1. Set the AutoSize property of the Control to true.
2. Enable the application framework by checking the “Enable Application Framework†on the Project Properties->Application page.
3. Define a Sub Main and set the Application.SetCompatibleTextRenderingDefault to false.
Back to the top
More Information
To reproduce the issue,
1. Create a new Visual Basic Windows Application in Visual Studio 2005.
2. Add a label to Form1 and change its AutoSize to false.
3. Change the label  text to a long string  and resize its width so that the width is just wide enough to encapsulate the label’s text.
4. In the Project Properties->Application page, uncheck the “Enable Application Frameworkâ€.
5. Now run the application and notice that some of the text in the label is truncated.
6. Add a new Module to the application and add the following code to the module.
    Public Sub main()
       Application.SetCompatibleTextRenderingDefault(False)
       Application.Run(New Form1())
    End Sub
7. Build and run the application, notice that the text is not truncated.
For more information on Application.SetCompatibleTextRendering, see the following MSDN article:
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.setcompatibletextrenderingdefault.aspx (http://msdn.microsoft.com/en-us/library/system.windows.forms.application.setcompatibletextrenderingdefault.aspx)
Back to the top
DISCLAIMER
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALSâ€) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
Back to the top
APPLIES TO
| • | Microsoft Visual Basic 2005 |
| • | Microsoft Visual Studio 2005 Standard Edition |
| • | Microsoft Visual Studio 2005 Professional Edition |
| • | Microsoft Visual Studio 2005 Team Suite |
Back to the top
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please