Note that there are some explanatory texts on larger screens.

plurals
  1. POAnti-Aliased Text in a Transparent .NET Form
    primarykey
    data
    text
    <p>I have a C# application which shows the current time in a transparent .NET Form. The Form has no controls and no border. Its property TransparencyKey is set to the Form's background color "light gray" to make it transparent.<br> So the user can only see the text (current time).</p> <p>The text is drawn in the PaintEventHandler:</p> <pre><code>private void Display_Paint( object sender, PaintEventArgs e ) { Graphics formGraphics = e.Graphics; Font myFont = new Font( "Microsoft Sans Serif", 24, FontStyle.Bold ); formGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; //formGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel; formGraphics.DrawString( "00:00:00", myFont, Brushes.Green, 0.0F, 0.0F ); myFont.Dispose(); } </code></pre> <p>Due to the anti-aliasing the text "00:00:00" is shown frayed when the Form is over a dark background. For light backgrounds the text is o.k.</p> <p>This image shows the problem and the good case:</p> <p><a href="http://www.habermann-net.de/public/development/antiAliasing_bad.png">text shows fringes due to anti-aliasing for dark background http://www.habermann-net.de/public/development/antiAliasing_bad.png</a></p> <p>Obviously Windows does render the text in a way that it fits to the Form's own background color and not in a way that it fits to the background which is behind the transparent Form.</p> <p>Is it possible to let Windows take the background behind the Form into account when rendering the text so that I get rid of the fringes? </p> <p>One "solution" could be to switch off anti-aliasing by setting TextRenderingHint accordingly. But up to now this is not my preferred "solution".</p> <p>System:<br> Windows XP, SP 3, .NET 3.5, VS 2008</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload