Draw a line in TextBox C # (.NET 3.5)

I need a text box with a bottom line, such as the input fields used in forms.

I was looking for functionality, such as a single border at the bottom, or something like that. But I think the only way is to draw one line in the text box.

The following code does not 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 can help! Thank!

+3
source share
3 answers

Please see Rendering the owner of a Windows.Forms TextBox article , which describes the setup process.

+3
source

How to use RichtextBox control and underline text?

0

, TextBox . TextBox WM_PAINT (, WM_NC_PAINT ).

EDIT
answer sash gives a link that shows you how to do what I said here.

EDIT 2
For your example, is it enough to install Borderon noneand add TextBoxto the panel? You can then draw the panel to have the bottom line, and until TextBoxit fills the panel, it will also be visible. This, however, only works for single-line TextBoxes.

0
source

Source: https://habr.com/ru/post/1732999/


All Articles