如何使用C#在我的Windows窗体中一次按钮 [英] how to buttonwork at once in my windows form using C#

查看:89
本文介绍了如何使用C#在我的Windows窗体中一次按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是按钮形式。

如果我填写数字并单击按钮意味着它显示答案,如果我再次点击它显示我的答案的两倍...这里如何阻止按钮点击不超过一次。或者它只执行一次。

这里是我的编码:

hi here my problem is button in form.
if i fill the number and click the button mean it shows answer, if i click again it show double of my answer... here how to block button click not more than one time. or it execute at only once.
here is my coding:

 if (chk_yoga.Checked)
  {
if (cb_duration.Text == "DAY")
{
    day = 1;
    nday = Convert.ToInt32(cb_days.Text);
    inetamt = inetamt + yoga * nday * day;
    txt_inetamt.Text = inetamt.ToString();
}

 if (cb_duration.Text == "MONTH")
{
     day = 30;
     nday = Convert.ToInt32(cb_days.Text);
    inetamt = inetamt + yoga * nday * day;
    txt_inetamt.Text =inetamt.ToString();
}





这里我带有一些像yoga = 200的值,我有3种类型的值计算...每天,每月,每个会话。



here i carry some value in like yoga= 200, i have 3 type of value calculate ...per day , per month, per session.

推荐答案

如果你真的希望它只执行一次,那么设置
If you truly want it to execute only once, then set
myButton.Enabled = false;

。然后,您可以在发生某些事情时将其设置为再次启用,这样可以重新计算值 - 例如,ComboBox选择中的更改,或者 yoga 的值的更改,或者 nday 等等。

at the end of the routine. You can then set it to enabled again when something happens which makes recalculation worth while - a change in the ComboBox selection for example, or a change in the value of yoga, or nday and so forth.


这篇关于如何使用C#在我的Windows窗体中一次按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆