Description of the Program file in winform and the Application. SetCompatibleTextRendering letter

Source: Internet
Author: User

When creating an Application, we found that our From form was called through the Program file, but what does the method in the Main function in the Program file mean?
First, there are three lines of code under the Main function.
Application. EnableVisualStyles ();
Application. SetCompatibleTextRenderingDefault (false );
Application. Run (new Form1 ());
Next we will explain it one by one:
The Application. EnableVisualStyles method enables visual styles for the Application. If the controls and Operating Systems Support visual styles, the controls are drawn in visual styles. To EnableVisualStyles take effect, you must call it before creating any control in the application. EnableVisualStyles is usually the first line of the Main function. When you call EnableVisualStyles, you can enable the visual style without a separate list.
The Application. SetCompatibleTextRenderingDefault function is interpreted:
Some Windows Form Controls can use the TextRenderer Class Based on the GDI Graphics library) or the Graphics class based on the GDI + Graphics library) to present their text. This change is made in. NET Framework2.0 considering performance and localization issues related to GDI +. Use SetCompatibleTextRenderingDefault to set the default value for this attribute for controls that support the UseCompatibleTextRendering attribute.
The UseCompatibleTextRendering attribute is designed to provide visual compatibility between Windows Forms controls and. NET Framework1.0 and. NET Framework1.1 applications using the Graphics class for custom text rendering. In most cases, if your application is not upgraded from. NET Framework1.0 or. NET Framework1.1, we recommend that you set UseCompatibleTextRendering to the default value of false. The GDI-based TextRenderer class is introduced in. NET Framework 2.0 to improve performance, improve text appearance, and enhance support for international fonts. In earlier versions of the. NET Framework, the Graphics class-based GDI + is used to execute all text rendering. GDI calculates the Character spacing and line breaks in different ways than GDI +. In a Windows Forms application that uses the Graphics class to render text, this may lead to a different display of the control text displayed using TextRenderer than other text in the application. To resolve this incompatibility, set the UseCompatibleTextRendering attribute to true. To set UseCompatibleTextRendering of all supported controls in the application to true, use the true parameter to call the SetCompatibleTextRenderingDefault method.
Do not call this method if the Windows form code, such as Internet Explorer, is carried in another application. This method is called only in an independent Windows Forms application ."
Next, we will focus on how to solve this problem? If it is an old code (such as VB) or the original call thread does not set the Application. setCompatibleTextRenderingDefault (false) or directly set Application. setCompatibleTextRenderingDefault (true), some winfrom controls may have problems (such as Label) during display ).
Solution: directly set the display of the control to be incompatible with the old version.
Code:
Label label = new Label ();
Label. UseCompatibleTextRendering = false;
In this way, you can make the control incompatible with the rendering of the old version when the global version is compatible with the old version, so that the control will avoid errors when rendering text.

This article is from the "Zhang Xiaoyong" blog and will not be reproduced!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.