- This topic helps to draw border to any controls in C#.
- Here we show how to draw border around the TextBox control in C#.
C#.NET – Draw border around any controls in C#
- C# is an Object Oriented Programming language from Microsoft that mainly combines the computing power of C++ with the programming ease of Visual Basic.
- C# is mainly based on C++.
- The most recent version is C#4.0.
- C# language is simple, modern, general-purpose, object-oriented language.
Graphics Class – Draw border around any controls in C#
- Graphics class encapsulates a GDI+ drawing surface.
- This class cannot be inherited.
Assembly: System.Drawing (in System.Drawing.dll)
- Syntax for Graphics Class
public sealed class Graphics : MarshalByRefObject,
Draw border around the Textbox control or any controls in C# – Working
- First you have to add a TextBox control to the form for drawing border around the TextBox in C#.
- Then we draw border around the TextBox control using graphics class, this is done by drawing rectangle around the border of the TextBox controls in C#.
Draw border around the Textbox control or any controls in C# – Complete Code
public partial class Form1 : Form
private void Form1_Paint(object sender, PaintEventArgs e)
using (Graphics g = e.Graphics)
using (Pen pen = new Pen(Color.Red, 2))
foreach (Control ctr in this.Controls)
if (ctr is TextBox)
g.DrawRectangle(pen, new Rectangle(ctr.Location, ctr.Size));
Note: Draw borders around other controls, just change name ‘TextBox’
If you have any doubts in how to create border around any controls in C#, please feel free to contact us… our mail id: email@example.com
Draw border around any controls in C#