如何创建多个 RichTextBox
How to create multiple RichTextBoxes
我需要根据用户输入创建一定数量的 RichTextBox。
我可以使用工具箱在 visual studio 中创建一个,但是如何通过代码创建多个?
更新:
这是我的代码:
RichTextBox richTextBox = new RichTextBox();
richTextBox.Location = new Point(12, 169);
richTextBox.Width = 62;
richTextBox.Height = 76;
this.Controls.Add(richTextBox);
当我 运行 这个
时没有任何反应
调用 this.Refresh()
刷新 Control
并重新绘制其中的所有子项。
来自Docs:
Forces the control to invalidate its client area and immediately redraw itself and any child controls.
好的。这是一个显示它有效的示例:
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();
}
我需要根据用户输入创建一定数量的 RichTextBox。 我可以使用工具箱在 visual studio 中创建一个,但是如何通过代码创建多个?
更新:
这是我的代码:
RichTextBox richTextBox = new RichTextBox();
richTextBox.Location = new Point(12, 169);
richTextBox.Width = 62;
richTextBox.Height = 76;
this.Controls.Add(richTextBox);
当我 运行 这个
时没有任何反应调用 this.Refresh()
刷新 Control
并重新绘制其中的所有子项。
来自Docs:
Forces the control to invalidate its client area and immediately redraw itself and any child controls.
好的。这是一个显示它有效的示例:
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();
}