NumericUpDown.ValueChanged 事件


在以某种方式更改 Value 属性后发生。Occurs when the Value property has been changed in some way.

 event EventHandler ^ ValueChanged;
public event EventHandler ValueChanged;
member this.ValueChanged : EventHandler 
Public Custom Event ValueChanged As EventHandler 


下面的代码示例演示如何使用此成员。The following code example demonstrates the use of this member. 在此示例中,事件处理程序报告 ValueChanged 事件的发生。In the example, an event handler reports on the occurrence of the ValueChanged event. 此报表可帮助你了解何时发生事件,并可帮助你进行调试。This report helps you to learn when the event occurs and can assist you in debugging. 若要报告多个事件或频繁发生的事件,请考虑将 MessageBox.Show 替换为 Console.WriteLine 或将消息附加到多行 TextBox中。To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

若要运行示例代码,请将其粘贴到包含名为 NumericUpDown1NumericUpDown 类型实例的项目中。To run the example code, paste it into a project that contains an instance of type NumericUpDown named NumericUpDown1. 然后,确保事件处理程序与 ValueChanged 事件关联。Then ensure that the event handler is associated with the ValueChanged event.

private void NumericUpDown1_ValueChanged(Object sender, EventArgs e) {

   MessageBox.Show("You are in the NumericUpDown.ValueChanged event.");
Private Sub NumericUpDown1_ValueChanged(sender as Object, e as EventArgs) _ 
     Handles NumericUpDown1.ValueChanged

   MessageBox.Show("You are in the NumericUpDown.ValueChanged event.")

End Sub


若要发生 ValueChanged 事件,可通过单击 "上移" 或 "下移" 按钮,或用户输入由控件读取的新值,在代码中更改 Value 属性。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. 当用户按 ENTER 键或离开控件时,会读取新的值。The new value is read when the user hits the ENTER key or navigates away from the control. 如果用户输入新值,然后单击向上或向下按钮,则 ValueChanged 事件将发生两次。If the user enters a new value and then clicks the up or down button, the ValueChanged event will occur twice.

有关处理事件的详细信息,请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.