我有1个标签和4个复选框。我想要做的是当选中复选框时,我希望价格在文本框中增加或减少,具体取决于复选框是否未选中。我迷失在如何做到这一点上。如何选择复选框时更改文本框的值C#winforms
标签TextBlock_Price
复选框有以下几种:phScreenRepair, virusRemoval, hardwareRepInstall, softwareInstall
我的代码:
public float? MultipleServiceAdder()
{
if (phScreenRepair.Checked)
{
return 20.00f;
}
if (virusRemoval.Checked)
{
return 10.00f;
}
if (hardwareRepInstall.Checked)
{
return 10.00f;
}
if (softwareInstall.Checked)
{
return 5.00f;
}
textBlock_Price.Text = "$0.00";
return 0f;
}
您有复选框[的CheckedChanged](https://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox.checkedchanged(V = vs.110)的.aspx)事件。请不要懒惰,并使用谷歌。 –
认为点击事件会起作用,CheckStateChanged会是最好的,因为当您点击,移动点击等等时会发生多种事情...... @ bruno.almeida –