Hi,
I am trying to apply text border to some text I am drawing.
I obtained some code from Bob Powells GDI+ FAQ but it seems that the text
border is draw from outside inwards, that is the letter thickness decreases.
What I need is for the border to be drawn from outside outwards, so the
letter thickness stays the same but the border is drawn on the outside.
Also I have problem when drawing against a white or light coloured
background whereby the text border is not drawn very well and looks messy.
Code:
backBuffer=new Bitmap(this.ClientSize.Width,this.ClientSize.Heigh t);
Graphics g = Graphics.FromImage(backBuffer);
// back rectangle
Rectangle backRectangle = new Rectangle(0, 0, panel1.Width, panel1.Height);
SolidBrush backBrush = new SolidBrush(Color.WhiteSmoke);
// Create background fill
g.FillRectangle(backBrush,backRectangle);
// Create the actual graphics path that is going to be used
GraphicsPath path = new GraphicsPath();
Pen penBorder = new Pen(Color.Black, borderSize);
path.AddString("Test Text",
new FontFamily("Tw Cen MT"), (int)System.Drawing.FontStyle.Regular, textSize
+ borderSize,
new Point(x, y), StringFormat.GenericTypographic);
// Get the bounds so we can inflate it and draw the background rectangle
RectangleF rect = path.GetBounds();
rect.Inflate(2.0f, 2.0f);
// Draw the background rectangle
g.FillRectangle(brush, rect);
// Draw the text using the graphics path
g.FillPath(new SolidBrush(Color.White), path);
g.DrawPath(penBorder, path);
g.Dispose();
// Copy the back buffer to the screen
e.Graphics.DrawImageUnscaled(backBuffer, 0, 0);