Search code examples
c#winforms.net-3.5textbox

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!


Solution

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