确定是否变更事件从用户输入或不发生或不、发生、事件、用户

2023-09-04 09:35:13 作者:滥滥滥滥滥滥ゞ情

在C#中,更改事件的控制(例如,一个的NumericUpDown)被炒鱿鱼的值是由用户直接更改,或者如果它被编程改变一些其他事件的结果。

有没有一种方法,以确定该事件是否发生作为用户输入的结果?例如,无论是手动更改NumericUpDown1中的价值,并点击按钮1,将显示价值变化。如果我只是想显示值改为如果它是通过在控制,而不是点击按钮1的结果?

上/下箭头用户点击修改

 私人无效numericUpDown1_ValueChanged(对象发件人,EventArgs的)
    {
        的MessageBox.show(值改为);
    }

    私人无效button1_Click_1(对象发件人,EventArgs的)
    {
        numericUpDown1.Value = 3;
    }
 

解决方案

有没有好的办法做到这一点。你可以找到解决方法的具体情况,例如,

听的MouseDown或什么,而不是的valueChanged上的数字降下来了。

在设置按钮单击事件处理一个标志,将禁止该消息框无法显示。

CustomerWise 9.2新功能介绍 项目管理者联盟

一般来说,你应该尽量组织的方式表单,它不无论身在何处的价值得到了改变。

In C#, the Changed event for a control (say, a numericupdown) gets fired whether the value was change directly by the user or if it was changed programatically as the result of some other event.

Is there a way to determine whether the event occurred as a result of user input? For example, both manually changing the value of numericUpDown1 and clicking on button1 will display "value changed". What if I only wanted to display "value changed" if it was changed through the user clicking on the up/down arrows in the control and not as a result of clicking on button1?

    private void numericUpDown1_ValueChanged(object sender, EventArgs e)
    {
        MessageBox.Show("value changed");
    }

    private void button1_Click_1(object sender, EventArgs e)
    {
        numericUpDown1.Value = 3;
    }

解决方案

There is no nice way to do it. You can find workarounds for specific cases, e.g.

listen to MouseDown or something instead of valueChanged on the numeric drop down.

Set a flag in button click event handler that will prohibit the message box from showing.

In general you should try to organize your form in a way that it doesn't matter where the value got changed.