[英]Change TextBox width when index has changed
i have a project and i want to resize the textboxes width so as to fit to the text i set. 我有一个项目,我想调整文本框的宽度,以适合我设置的文本。
I tried the code below but not all of the text is showing. 我尝试了下面的代码,但并未显示所有文本。 Specificly, i have a List named input where i save the txt file i read, line by line, using stream reader.
具体来说,我有一个名为输入的列表,其中使用流阅读器逐行保存读取的txt文件。
Then i want to resize the textbox width to show all the line. 然后,我想调整文本框的宽度以显示所有行。 I'm not allowed to use a richtextbox, so i need your help!!
我不允许使用Richtextbox,所以我需要您的帮助!
for (int count = 0; count < input.Count; count++)
{
TextBox tb = new TextBox();
tb.Name = "text_Box_line" + count.ToString();
tb.Text = input[count].ToString();
Point p = new Point(100, 30 * count);
tb.Location = p;
Size size = TextRenderer.MeasureText(tb.Text, tb.Font);
tb.Width = size.Width;
tb.SelectionStart = tb.Text.Length;
tb.ScrollToCaret();
this.Controls.Add(tb);
}
for example, the text i want to show is: 例如,我要显示的文本是:
"[00400000] 00000000 main" “ [00400000] 00000000主”
and the shown text is 并且显示的文字是
" 00000000 main" “ 00000000主”
Any reason you can't use the built in autosizer? 有什么原因不能使用内置的自动大小调整器?
for (int count = 0; count < input.Count; count++)
{
TextBox tb = new TextBox();
tb.Name = "text_Box_line" + count.ToString();
tb.Text = input[count].ToString();
Point p = new Point(100, 30 * count);
tb.Location = p;
tb.AutoSize = True;
tb.SelectionStart = tb.Text.Length;
tb.ScrollToCaret();
this.Controls.Add(tb);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.