【发布时间】:2022-01-08 04:44:27
【问题描述】:
如何设置按钮的标签?
这是我的代码:
private void InitializeMyButton()
{
// Create and initialize a Button.
Button button1 = new Button();
// Set the button to return a value of OK when clicked.
button1.DialogResult = DialogResult.None;
// Add the button to the form.
Controls.Add(button1);
}
希望有人能找到解决办法。
【问题讨论】:
-
你为什么不用
button1.Text? -
button1.Text = "OK Button"; -
button1.Text = "有趣的名字";
-
您清楚地找到了the docs,因为您的代码是直接从中提取的 - 您是否寻找过可能设置按钮的
Text的东西? -
术语很重要。标签是一个控件。按钮也是如此。两者都有一个 .Text 属性。