UseCompatibleTextRendering - Compatible with whaaaaaat?

There seems to be quite a bit of confusion around this little old flag that has cropped up in VS 2005. 

In Windows Forms 2.0, we added support for drawing GDI text. At first we had grandiose plans of poking and prodding at the DrawText API such that we could make it match up exactly how GDI+'s DrawString API works.  I actually think we got pretty close, but there are fundamental differences in word wrapping and character spacing that as mere consumers of the both APIs, Windows Forms could not solve.

So now we're presented with a problem: we want to switch everyone over to the new TextRenderer APIs so text will look better, localize better, draw more consistently with other dialogs in the operating system... ...but we dont want to break folks counting on GDI+ measure string for calculations of where their text should line up.

Long story short UseCompatibleTextRendering means "compatible" with version 1.0 and 1.1 of the framework. If you built your app using Visual Studio 2003, running your app on version 2.0 of the framework should *just* work.

In order to easily switch ALL of your controls over to the new GDI TextRenderer, use Application.SetCompatibleTextRenderingDefault(). 

Note an individual control when it is painting/measuring checks it's value of UseCompatibleTextRendering to do its decision making between GDI/GDI+ measuring/drawing so setting the value of this property directly on the control trumps whatever you've set in Application's handy helper method.

In summary

Control.UseCompatibleTextRendering
Sets/Gets whether a control should use GDI+ or GDI for text drawing.

True Use GDI+/Graphics.DrawString Behaves same as 1.1
False Use GDI/TextRenderer Behaves similar to 1.1, looks nicer, localizes better

Application.SetCompatibleTextRenderingDefault
Handy helper method for setting UseCompatibleTextRendering on ALL of your controls.

Oh, and one more thing...

When you switch over to UseCompatibleTextRendering = false (which I know you'll want to), if you were using graphics.MeasureString, you will want to move over to TextRenderer.MeasureText. As noted above there are differences in how the two technologies word wrap, character space etc. 

A common case for using MeasureString is figuring out how to size your label control. Instead of blindly moving over to TextRenderer.MeasureText, I would recommend just calling label.GetPreferredSize( ) with the same constraints you were passing into MeasureString. This will correctly switch between the two measuring technologies, you dont have to create a graphics object, and it may even help your perf a little. (no guarantees on the last one, but sometimes this value is cached.)