forum

Home / DeveloperSection / Forums / C# windows form text outline?

C# windows form text outline?

Samuel Fernandes 4820 23-Dec-2013

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
        };
        g.FillRectangle(
         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);
        drawBrush.Dispose();
        sf.Dispose();
        ControlPaint.DrawBorder(
                e.Graphics, btnHeader.ClientRectangle,
                    Color.Black,3,ButtonBorderStyle.Solid,
                    Color.Black,3,ButtonBorderStyle.Solid,
                    Color.Black,3,ButtonBorderStyle.Solid,
                    Color.Black,3,ButtonBorderStyle.Solid
        );
    }


c# c# 
Updated on 23-Dec-2013

Can you answer this question?


Answer

1 Answers

Liked By