- This topic explains how to draw hollow text in C#
- It is done with the help of drawing class in C#. All are done in the form paint event.
DRAWING CLASS – How to draw hollow text in C#
- System.Drawing namespace provides access to GDI+ basic graphic functionality.
- Main functions of Drawing are
System.Drawing.Drawing2D
System.Drawing.Imaging
System.Drawing.Text
- Graphics class provide methods for drawing to the display devices.
- Rectangle and Point Class encapsulates GDI+ primitives.
- Pen Class is used to draw lines and curves.
- Brush Class is used to fill interiors of shapes.
Graphics.DrawRectangle Method – How to draw hollow text in C#
- Draws a rectangle specified by a coordinate pair, a width, and a height.
Pen Class – How to draw hollow text in C#
- Defines an object used to draw lines and curves. This class cannot be inherited.
Graphics.SmoothMode Property - How to draw hollow text in C#
- It helps to get or set the rendering quality for this Graphics.
Namespace: System.Drawing
Assembly: Â System.Drawing (in System.Drawing.dll)
- Syntax
|
1 2 3 |
// Declaration public SmoothingMode SmoothingMode { } |
Graphics.DrawPath Method – How to draw hollow text in C#
- Helps to draw a graphics path
- Syntax
|
1 2 3 |
// Declaration public void DrawPath(Pen pen, GraphicsPath path) { } |
Graphics.FillPath Method - How to draw hollow text in C#
- Helps to fill the interior of the graphics path
- Syntax
|
1 2 3 |
// Declaration public void FillPath(Brush brush, GraphicsPath path) { } |
How to draw hollow text in C# - Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //draw again when maximize this.ResizeRedraw = true; } private void Form1_Paint(object sender, PaintEventArgs e) { // Make things smoother. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; // Create the text path. GraphicsPath path = new GraphicsPath(FillMode.Alternate); // Draw text using a StringFormat to center it on the // form. using (FontFamily font_family = new FontFamily("Times New Roman")) { using (StringFormat stringformat = new StringFormat()) { stringformat.Alignment = StringAlignment.Center; stringformat.LineAlignment = StringAlignment.Center; path.AddString("Hollow Text" + "Hollow Text", font_family, Convert.ToInt32(FontStyle.Bold), 100, this.ClientRectangle, stringformat); } } // Fill and draw the path. e.Graphics.FillPath(Brushes.Azure, path); using (Pen pen = new Pen(Color.Blue, 3)) { e.Graphics.DrawPath(pen, path); } } } } |
How to draw hollow text in C#






