Home > DeveloperSection > Forums > C# windows form text outline?
Samuel Fernandes
Samuel Fernandes

Total Post:159

Posted on    December-23-2013 2:54 AM

 C# C# 

 1 Reply(s)
 3343  View(s)
Rate this:

I'm trying to make the text outline. I use this code and got two errors in

using (GraphicsPath = GetStringPath(s, dpi, rect, font, format))


    g.DrawPath(Pens.Black, path);


The visual studio under lines GraphicsPath and path

Here is my code's overview.

  GraphicsPath GetStringPath(string s, float dpi, RectangleF rect, Font font, StringFormat format)


        GraphicsPath path = new GraphicsPath();

        // Convert font size into appropriate coordinates

        float emSize = dpi * font.SizeInPoints / 72;

        path.AddString(s, font.FontFamily, (int)font.Style, emSize, rect, format);

        return path;


    private void btnHeader_Paint(object sender, PaintEventArgs e)


        Graphics g = e.Graphics;

        String s = "P9 area Terminal 1";

        dynamic btn = (Button)sender;

        dynamic drawBrush = new SolidBrush(btn.ForeColor);

        dynamic sf = new StringFormat


            Alignment = StringAlignment.Center,

            LineAlignment = StringAlignment.Center



         new System.Drawing.Drawing2D.LinearGradientBrush(PointF.Empty, new PointF(0, btn.Height), Color.CornflowerBlue, Color.MediumBlue),

         new RectangleF(PointF.Empty, btn.Size));

        btnHeader.Text = string.Empty;

        RectangleF rect = this.ClientRectangle;

        Font font = this.Font;

        StringFormat format = StringFormat.GenericTypographic;

        float dpi = g.DpiY;

        using (GraphicsPath = GetStringPath(s, dpi, rect, font, format))


            g.DrawPath(Pens.Black, path);


        g.DrawString(s, btn.Font, drawBrush, e.ClipRectangle, sf);




                e.Graphics, btnHeader.ClientRectangle,







Pravesh Singh

Total Post:412

Posted on    December-23-2013 5:11 AM

Hi Samuel,

You're not storing the return value of GetStringPath appropriately. Try this:

using (var path = GetStringPath(s, dpi, rect, font, format))


    g.DrawPath(Pens.Black, path);


If this doesn't work, then update your original question with the exact error messages you're getting.

Don't want to miss updates? Please click the below button!

Follow MindStick