我有一个C#按钮,让我们说'开/关':
我想改变'OFF',当我们第一次点击它并运行buttonOFF()当我们再次点击时,它会变为'ON'并运行buttonON()
等等..
这样做的正确方法是什么?我可以在一个onClick事件中完成所有操作吗?和平的小榜样会很有用.谢谢 !
private void buttonON()
{
// Magic here
}
private void buttonOFF()
{
// Magic here
}
protected void button_click(object sender, EventArgs e)
{
if ( button.Text == "ON" )
{
button.Text = "OFF";
this.buttonOFF();
}
else
{
button.Text = "ON";
this.buttonON();
}
}
Run Code Online (Sandbox Code Playgroud)
您最好使用此方法.使用带按钮外观的复选框
CheckBox checkBox1 = new System.Windows.Forms.CheckBox();
checkBox1.Appearance = System.Windows.Forms.Appearance.Button;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1272 次 |
| 最近记录: |