NumericUpDown的TextChanged事件 [英] TextChanged Event of NumericUpDown

查看:544
本文介绍了NumericUpDown的TextChanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Visual C#2010 Express.当我使用箭头更改numericUpDown的值时,我的按钮将变为启用状态.但是,当我通过直接更改文本来更改numericUpDown的值时,我也想启用我的按钮.

I am using Microsoft Visual C# 2010 Express. When i change the value of numericUpDown using arrows, my button becomes enable. But i also want to enable my button when i change the value of numericUpDown by changing the text directly.

我正在使用以下代码:

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
    button1.Enabled = true;
}

推荐答案

您可能需要使用

You may need to use TextChanged event instead of using ValueChanged. The Value changed event need you to press enter key after changing value to get ValueChanged fired.

MSDN对NumericUpDown.ValueChanged事件的看法

What MSDN say about NumericUpDown.ValueChanged Event

要发生ValueChanged事件,可以更改Value属性 在代码中,通过单击向上或向下按钮,或通过用户输入 控件读取的新值. 当 用户点击ENTER键或离开控件.如果 用户输入一个新值,然后单击向上或向下按钮, ValueChanged事件将发生两次, MSDN .

For the ValueChanged event to occur, the Value property can be changed in code, by clicking the up or down button, or by the user entering a new value that is read by the control. The new value is read when the user hits the ENTER key or navigates away from the control. If the user enters a new value and then clicks the up or down button, the ValueChanged event will occur twice, MSDN.

绑定TextChanged事件.

private void TestForm_Load(object sender, EventArgs e)
{
    numericUpDown1.TextChanged += new EventHandler(numericUpDown1_TextChanged);
}

TextChanged事件的声明.

void numericUpDown1_TextChanged(object sender, EventArgs e)
{
    button1.Enabled = true;
}

这篇关于NumericUpDown的TextChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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