c# - 如何创建多个 RichTextBox
问题描述
我需要根据用户输入创建一定数量的 RichTextBoxes。我可以使用工具箱在 Visual Studio 中创建一个,但我将如何通过代码创建多个?
更新:
现在这是我的代码:
RichTextBox richTextBox = new RichTextBox();
richTextBox.Location = new Point(12, 169);
richTextBox.Width = 62;
richTextBox.Height = 76;
this.Controls.Add(richTextBox);
当我运行它时没有任何反应
解决方案
好的。这是一个显示它有效的示例:
void Main()
{
Form f = new Form();
Button b = new Button();
b.Click += (sender, args) =>
{
RichTextBox richTextBox = new RichTextBox
{
Name = "rtbBlahBlah",
Location = new System.Drawing.Point(12, 169),
Width = 62,
Height = 76
};
f.Controls.Add(richTextBox);
};
f.Controls.Add(b);
f.Show();
}