【发布时间】:2012-02-18 10:29:05
【问题描述】:
我正在使用 Winform。我已经设置了 20 个按钮和上下按钮,如下所示。 这些按钮的文本值为 button1 = 1;按钮 2 = 2; ... button20 =20 在开始时间。我已经这样做了。
当我按下向下按钮时,20 个按钮的文本已更改为 21 到 40;和向上按钮返回 1 到 20。
btn_Down click event
button21.Text = "21";
button22.Text = "22";
...
..
button40.Text = "40";
and btn_Up Click event
btn_Down click event
button1.Text = "1";
button2.Text = "2";
...
..
button20.Text = "20";
有什么简单的编码方法吗?
更新-
当我尝试 sll 代码时,。
int index = 0;
foreach (var control in this.tableLayoutPanel1.Controls)
{
var button = control as Button;
if (button != null)
{
button.Text = String.Format("{0}", index);
index++;
}
}
我得到了下面。上下也变了,数字顺序倒了。
请更新答案。
【问题讨论】:
-
你想实现什么,因为我无法理解“但是当我按下向下按钮时,20 个按钮的文本已更改为 21 到 40;向上按钮返回 1 到 20。 "
-
我想要 For(i=1;i
-
using System.Linq; form.Controls.OfType<Button>().ForEach(b => b.Text = "...");
标签: c# winforms windows-forms-designer