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

后端 未结 4 558
小蘑菇
小蘑菇 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: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

提交回复
热议问题