以编程方式使文本框多行

问题描述 投票:0回答:1

我正在这样的运行时中创建我的文本框:

TextBox control = new TextBox();                        
control.Name = "txt" + "somename";

上网查了一下,Textbox里应该有Multiline-Property,可惜没找到。 我也尝试添加多行,但这也不起作用。

我怎样才能在我的代码中做到这一点? 我使用 Windowsforms 和 .NET Framework 4.7.2

c# textbox programmatically-created
1个回答
1
投票
control.Multiline = true;

这将使您的文本框多行。这是一个完整的示例:

var textBox = new TextBox
{
  Multiline = true
};

textBox.Text = "FirstLine" + Environment.NewLine + "SecondLine";
© www.soinside.com 2019 - 2024. All rights reserved.