Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw Line in TextBox C# (.NET 3.5)

i need a textbox with a bottom-line such like inputfields used in forms.

I had looked for a functionality like single border on bottom, or something like this. But i think the only way is to draw a single line in a textbox.

The following code doesn't work:

private void textEdit1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        if (sender is TextBox)
        {
            TextBox tmp = (TextBox)sender;
            Graphics g = CreateGraphics();
            Pen p = new Pen(System.Drawing.Color.Red, 8);
            g.DrawLine(p, tmp.Location.X, tmp.Location.Y, (tmp.Location.X + tmp.Width), tmp.Location.Y);
            p.Dispose();
            g.Dispose();
        }
    }

Hope someone could help! Thanks!

like image 571
user274342 Avatar asked Dec 21 '25 04:12

user274342


1 Answers

Please look at Owner-drawing a Windows.Forms TextBox article which describes customization process.

like image 105
sashaeve Avatar answered Dec 22 '25 19:12

sashaeve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!