Change WinForms TextBox to BorderStyle. Nobody Cuts Text

I changed the WinForms TextBox control to have no border.

When I do that, the bottom pixel of a line of text in a field is cropped.

Top: BorderStyle.Fixed3D (default). Bottom: BorderStyle.None

enter image description here

You can see that the last bit of text in the restricted text field is disabled:

enter image description here

How to convince a TextBox (whose height cannot be changed) that it should be higher?

+4
source share
4 answers

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

 public class TextBoxEx : TextBox { public TextBoxEx() { base.AutoSize = false; } } 
+1
source

This seems like a 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
source

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 text box to "accept" a new size

0
source

You can also fix this in Designer Visual Studio.

Change the height in the minimum size property for the text box. Go to multiline = true and then go back to false. The text box will change and remain fixed.

No code changes are required.

-1
source

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


All Articles