TextBox with bottom border

前端 未结 1 1346
有刺的猬
有刺的猬 2021-01-15 08:55

I want to have TextBox with bottom border but Graphics drawn for TextBox is distorted/broken on resize because of Color.Transparent.

相关标签:
1条回答
  • 2021-01-15 09:41

    To have a TextBox with bottom border, The most simple workaround that I can offer is docking a 1 pixel height lable (or other control) to bottom of the TextBox:

    using System.Drawing;
    using System.Windows.Forms;
    public class MyTextBox : TextBox
    {
        public MyTextBox()
        {
            BorderStyle = System.Windows.Forms.BorderStyle.None;
            AutoSize = false; //Allows you to change height to have bottom padding
            Controls.Add(new Label()
                        { Height = 1, Dock = DockStyle.Bottom, BackColor = Color.Black });
        }
    }
    
    0 讨论(0)
提交回复
热议问题