我想要点击图片来启动按钮点击事件。 但是怎么样? ButtonPlus每次都会达到+1,如果达到5/10 ......它会激活另一张图像。
通过点击加号按钮来增加浪费时间,我想点击图像,例如第一个(获取值5)并执行button_click代码。
我想通过将ButtonPlus值设置为4,并转发到button_click事件,它变为值5,并进行切换。
private void button1_Click(object sender, EventArgs e)
{
if (MaxPunkte > 0)
{
if (ButtonPlus1 < 30)
{
ButtonPlus1 += 1;
MaxPunkte += -1;
LabelAnzeige1 = ButtonPlus1;
label1.Text = LabelAnzeige1.ToString();
label5.Text = MaxPunkte.ToString();
label7.Text = (LabelAnzeige1 * 10).ToString();
label8.Text = label7.Text;
#region Switch
switch (ButtonPlus1)
{
case 5:
pictureBox1.Image = TraitCalc.Resources.HexagonSmall_5_active;
break;
case 10:
pictureBox2.Image = TraitCalc.Resources.HexagonBig_10_active_empty;
break;
case 15:
pictureBox3.Image = TraitCalc.Resources.HexagonSmall_15_active;
break;
case 20:
pictureBox4.Image = TraitCalc.Resources.HexagonBig_20_active_empty;
break;
case 25:
pictureBox5.Image = TraitCalc.Resources.HexagonSmall_25_active;
break;
case 30:
pictureBox6.Image = TraitCalc.Resources.HexagonBig_30_active_empty;
break;
}
#endregion
}
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
ButtonPlus1 = 4;
//and start button click event (adds +1 = 5 -> go to switch case 1)
}
答案 0 :(得分:2)
(或者您可以像任何其他方法一样调用button1_Click
。)
答案 1 :(得分:2)
为什么不直接调用按钮处理程序?
private void pictureBox1_Click(object sender, EventArgs e)
{
ButtonPlus1 = 4;
//and start button click event (adds +1 = 5 -> go to switch case 1)
button1_Click(null, null); // or whatever arguments you need,
// but you were not using them.
}