您好我正在尝试创建一个NumericUpDown按钮,但是我看不到任何涉及按下哪个按钮的事件(Up或Down我的意思)。如何查看用户按下的按钮?
答案 0 :(得分:1)
使用NumericUpDown.ValueChanged事件并将当前值保存到本地字段并检查天气是否大于或小于本地字段
答案 1 :(得分:0)
var oldValue = numericUpDown1.Value;
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
var newValue= numericUpDown1.Value;
if (oldValue < newValue))
{
// this is up button
}
else
{
//this is down button
}
}
这可能会对你有所帮助。我没有写%100正确,例如你必须将新值转换为int和blabla。但逻辑就是这样。您必须订阅numericupdown valuechanged事件
答案 2 :(得分:0)
以下内容对我有用。我想知道值是来自文本输入还是按钮。对鼠标单击进行编程后,就可以设置一个参数,以便ValueChanged事件知道。
private void nud1_MouseClick(object sender, MouseEventArgs e)
{
if (e.X <= nud1.Controls[1].Width+1) {
// Click is in text area
}
else {
if (e.Y <= nud1.Controls[1].Height / 2)
// Click is on Up arrow
else
// Click is on Down arrow
}
}