How to draw a line below textbox using Pen in C#

How to decorate Text box with custom Line in C# using Graphics and Pen classes.


Decorating a text box will be easy with Graphic class in C#.net . Suppose you wanna create a custom control and like to draw a custom Line , all you need to do is override the paint method and add the following code.

 private Color borderColor = Color.Salmon;
 private int borderSize = 2; 
protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics graph = e.Graphics;
            //Draw border
            using (Pen penBorder = new Pen(borderColor, borderSize))
            {
                penBorder.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
    graph.DrawLine(penBorder, 0, this.Height - 1, this.Width, this.Height - 1);
            }
        }

I hope the code snippet helps you and the following will also do the same

How to draw a rectangle around textbox in C#

How to draw rectangle around a Text box in C# using Graphics and Pen classes.


Decorating a text box will be easy with Graphic class in C#.net . Suppose you wanna create a custom control and like to draw a rectangle around it, override the paint method and add the following code.

 private Color borderColor = Color.Salmon;
 private int borderSize = 2; 
protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics graph = e.Graphics;
            //Draw border
            using (Pen penBorder = new Pen(borderColor, borderSize))
            {
                penBorder.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
 graph.DrawRectangle(penBorder, 0, 0, this.Width - 0.5F, this.Height - 0.5F);
            }
        }

Using the Graphics and Pen classes it will be easier to finish the Task.

I hope the code snippet helps you and the following will also do the same