views:

166

answers:

1

Hi All

I have seen many other samples out there that draw smooth text on glass. But I can't use them. I need every single label that gets added at runtime to be smooth. I can't just "draw" text onto the screen.

Is this at all possible, and are there and sources around?

Thank you

A: 

Hi,

Take a long at this article http://msdn.microsoft.com/en-us/magazine/cc163435.aspx#S6

It's a bit long but it answers alot of your question and alore more in regards to glass.

but the relevant part for you directly is

One particular gotcha is that rendering a GDI item in black uses the bit pattern 0x00000000-which also happens to be a completely transparent black if you are using an alpha channel. This means that if you draw with a black GDI brush or pen you'll get a transparent color, not a black one. The biggest problem this presents is when you try to use the default text color in a control of a text label that sits on the glass area. Since the default text color is usually black, the DWM will consider this to be transparent and the text will be written in the glass incorrectly. An example can be seen in Figure 10. The first line is written with GDI+, the second is a text label control using the default color. As you can see, it's nearly illegible because it's actually incorrectly rendered text that shows up as gray, not black.

Happily, there are a number of ways around this problem. Using owner-draw controls is one. Rendering to a bitmap that has an alpha channel is another. Fortunately, the easiest way to get text on controls is to let the .NET Framework 2.0 use GDI+ for you. This is easily accomplished by setting the UseCompatibleTextRendering property on your controls. By default, this property is set to false so that controls written for previous versions of the .NET Framework will render the same. But if you set it to true, your text will come out looking correct. You can set the property globally with the Application.SetUseCompatibleTextRenderingDefault method.

He also provides example code you can place in your Main()

static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(true);
    Application.Run(new GlassForm());
}

But I recommend reading the article, It'll clear up alot of what's going on with Aero/Glass

Cheers, Phyx

Phyx
Thank you, Phyx. that was the article that I originally read, everal times. Setting the Application.SetCompatibleTextRenderingDefault(true); to true makes no noticable difference on my machine.
lucifer
A slightly more work variant then: You could try creating a custom label that extends the normal Label. overriding the OnPaint event and using DrawThemeTextEx instead. http://stackoverflow.com/questions/2298819/using-drawthemetextex-in-c/2781072#2781072
Phyx
Thank you Phyx, looking at it now.
lucifer