我正在创建一个在线测试应用程序,其中我在表单加载时在运行时生成大约100个按钮。这是该段代码:
private void addQuestion_Reviewbutton()
{
for (int i = 1; i <= clsGlobalVars.gnTotalQuestion; i++)
{
Button button = new Button();
button.Location = new Point(160, 30 * i + 10);
button.Click += new EventHandler(ButtonClickOneEvent);
button.Tag = i;
button.Name = "Question" + i;
button.Text = i.ToString();
button.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.button));
button.BackgroundImageLayout = ImageLayout.Stretch;//.Zoom;
button.FlatAppearance.BorderSize = 0;
button.Size = new System.Drawing.Size(47, 41);
button.BackColor = Color.Transparent;
button.FlatStyle = FlatStyle.Flat;
button.Font = new System.Drawing.Font("Segoe UI Semibold", 12);
button.ForeColor = Color.White;
button.Cursor = Cursors.Hand;
flowLayoutPanel1.Controls.Add(button);
}
}
然后单击此按钮,我正在更改背景颜色。
void ButtonClickOneEvent(object sender, EventArgs e)
{
Button button = sender as Button;
//button.BackColor = Color.Yellow;
button.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.button_Orange));
lblQuestionNo.Text = ((int)button.Tag).ToString()+".";
btnNext.Focus();
}
我在名为“下一步”的表单上有一个按钮。现在的问题是,如果我当前遇到的问题是“ 1”。然后按下按钮,我想更改文本为“ 2”的按钮的背景图像。
我需要您的宝贵指导来解决此问题。