Bee Eee Blog

Tag: c# graphics gui .Net gdi+

c# drawing outlined text.

by brian on Mar.20, 2008, under .NET, GUI, c#, c# coding GUI, graphics

Here is a little nice bit of code to get text to jump out at you no matter what the background.  Outlined text is especially useful when putting text on an image and don’t have control of the background contrast. Basically it draws a black boarder with a while fill.

// prepare to draw text

StringFormat sf = new StringFormat();

sf.Alignment = StringAlignment.Center;

sf.LineAlignment = StringAlignment.Center;// draw the text to a path

System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

path.AddString(text, Font.FontFamily, 0, 14.0f, fillRect, sf);

// fill in the outline

g.FillPath(Brushes.White, path);

// draw the outline

g.DrawPath(new Pen(Color.Black,2.0f) , path);
1 Comment : more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...