问题
My problem with NumericUpDown control is when the user selects a value from NumericUpDown And unchecks the checkBox1 and clicks the Save button, the value of NumericUpDown not cleared:
Public Class FormAdd
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.StudenttableBindingSource.AddNew()
End Sub
Private Sub BttnSave_Click(sender As Object, e As EventArgs) Handles BttnSave.Click
Me.StudenttableBindingSource.EndEdit()
Me.StudenttableTableAdapter.Update(Me.StudentDataSet.studenttable)
Me.StudenttableTableAdapter.Fill(Me.StudentDataSet.studenttable)
MsgBox(" Student Saveed", MsgBoxStyle.Information)
Me.StudenttableTableAdapter.Fill(Main.StudentDataSet.studenttable)
Me.Close()
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = False Then
AgeNumericUpDown.Value = AgeNumericUpDown.Minimum
AgeNumericUpDown.Text = ""
End If
End Sub
I need if the user selects a value and unchecks the CheckBox1 value of AgeNumericUpDown to reset to an empty string.
Illustrated:

回答1:
Access the text control of the NumericUpDown
and then set text to be blank
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = False Then
AgeNumericUpDown.Controls.Item(1).Text = ""
End If
End Sub

回答2:
NumericUpDown does not contain string. It has value as numbers. So it should be:
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = False Then
AgeNumericUpDown.Value = 0
End If
End Sub
EDIT:
Check this out then if you don't want the value to be zero, but empty!
Private Sub BttnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BttnSave.Click
If AgeNumericUpDown.Value <> 0 Then
AgeNumericUpDown.Controls(1).Text = ""
End If
End Sub
来源:https://stackoverflow.com/questions/21831150/clearing-numericupdown