Changing WinForms TextBox to BorderStyle.None causes text to be cut off

后端 未结 4 521
小蘑菇
小蘑菇 2021-01-13 11:08

i\'ve changed a WinForms TextBox control to have no border.

When i do the bottom pixel row of text in the box is being cut off.

Top:

相关标签:
4条回答
  • 2021-01-13 11:30

    This seems to do the trick:

    public Form2()
    {
        InitializeComponent();
        textBox1.Multiline = true;
        textBox1.MinimumSize = new Size(0, 30);
        textBox1.Size = new Size(textBox1.Size.Width, 30);
        textBox1.Multiline = false;
    }
    
    0 讨论(0)
  • 2021-01-13 11:31

    The AutoSize property is there, just inherit from TextBox and you can get to the property:

    public class TextBoxEx : TextBox {
    
      public TextBoxEx() {
        base.AutoSize = false;
      }
    
    }
    
    0 讨论(0)
  • 2021-01-13 11:34

    You can do this in your form:

        private void RefreshHeight(TextBox textbox)
        {
            textbox.Multiline = true;
            Size s = TextRenderer.MeasureText(textbox.Text, textbox.Font, Size.Empty, TextFormatFlags.TextBoxControl);
            textbox.MinimumSize = new Size(0, s.Height + 1);
            textbox.Multiline = false;
        }
    

    Then you say RefreshHeight(textbox1);

    Multiline change will force the textbox to "accept" the new size

    0 讨论(0)
  • 2021-01-13 11:57

    You can also fix this in the Visual Studio Designer.

    Change the height in the minimum size property for the text box. Change to multiline=true, then back to false. The text box will resize and stay fix.

    No code changes needed.

    0 讨论(0)
提交回复
热议问题