---
title: "C# windows form text outline?"  
description: "C# windows form text outline?"  
author: "Samuel Fernandes"  
published: 2013-12-23  
updated: 2013-12-23  
canonical: https://www.mindstick.com/forum/1832/c-sharp-windows-form-text-outline  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# C# windows form text outline?

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to make the [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) outline. I use this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) and got two [errors](https://answers.mindstick.com/qa/116170/fresh-fir-against-gandhis-in-national-herald-case-cover-up-for-ed-s-own-errors) in

```
using (GraphicsPath = GetStringPath(s, dpi, rect, font, format)){                g.DrawPath(Pens.Black, path);}
```

The [visual studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) under lines GraphicsPath and [path](https://www.mindstick.com/articles/44333/4-expert-tips-on-how-to-pick-the-right-career-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        );    }
```

## Replies

### Reply by Pravesh Singh

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.


---

Original Source: https://www.mindstick.com/forum/1832/c-sharp-windows-form-text-outline

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
