gpt4 book ai didi

c# - "MouseUp"事件是否更改了 NumericUpDown 的值?

转载 作者:太空宇宙 更新时间:2023-11-03 20:25:13 24 4
gpt4 key购买 nike

我需要确定 NumericUpDown 控件的值是否被 mouseUp 事件更改

当 numericupdown 的值发生变化时,我需要调用一个昂贵的函数。我不能只使用“ValueChanged”,我需要使用 MouseUp 和 KeyUp 事件。

enter image description here

基本上,我需要知道:

Did the value of the numericUpDown change when the user let go of the mouse? If any area which is not highlighted in red is clicked, the answer is no. I need to IGNORE the mouse up event, when ANYWHERE but the red area is clicked.

我如何通过代码确定这一点?我发现事件有点困惑。

最佳答案

这将在用户释放鼠标按钮时触发。您可能想调查释放了哪个鼠标按钮。

编辑

    decimal numvalue = 0;
private void numericUpDown1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && numvalue != numericUpDown1.Value)
{
//expensive routines
MessageBox.Show(numericUpDown1.Value.ToString());
}

numvalue = numericUpDown1.Value;
}

编辑 2这将确定鼠标左键是否仍然按下,如果它在执行昂贵的例程之前退出,则对按下键盘按钮没有帮助。

    private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left)
{
return;
}
//expensive routines


}

编辑3

How to detect the currently pressed key?

将有助于解决按下任意键的问题,尽管我认为唯一重要的是方向键

关于c# - "MouseUp"事件是否更改了 NumericUpDown 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10980790/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com