清除NumericUpDown [英] Clearing NumericUpDown
问题描述
我对NumericUpDown控件的问题是,当用户从NumericUpDown中选择一个值并取消选中checkBox1并单击保存"按钮时,NumericUpDown的值未清除:
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
我需要用户选择一个值并取消选中AgeNumericUpDown的CheckBox1值以重置为空字符串.
I need if the user selects a value and unchecks the CheckBox1 value of AgeNumericUpDown to reset to an empty string.
说明:
推荐答案
我使用了不带旋转器的NumericUpDown控件,因为我只需要数字.该控件位于从列表视图选择中调用的子对话框中.当要加载到NumericUpDown控件中的值在listwiew中为零时,该控件中为零.始终必须清除零.这是我将其显示"为空白的方式.如果为零,则将控件的ForeColor更改为白色.我添加了一个Enter事件,该事件将ForeColor更改为黑色,并删除了零.
I was using the NumericUpDown control without the spinners because I wanted only numbers. The control was in a child dialog that was invoked from a listview selection. When the value to be loaded into the NumericUpDown control was zero in the listwiew, a zero was in the control. That zero always had to be cleared out. Here's how I made it "appear" blank. If it was zero, I change the ForeColor of the control to white. I added an Enter event that changed the ForeColor to black and deleted the zero.
这隐藏了NumericUpDown控件微调器.
This hid the NumericUpDown control spinners.
AccessCode.Controls[0].Visible = false;
这些语句采用初始化形式. (将可变代码加载到AccessCode中)
These statements were in the form initialization. (var code was to be loaded into AccessCode)
if (code == 0)
{
AccessCode.ForeColor = Color.White;
}
Enter事件代码如下所示.
The Enter event code looked like this.
private void AccessCode_Enter(object sender, EventArgs e)
{
if (AccessCode.ForeColor == Color.White)
{
AccessCode.ForeColor = Color.Black;
AccessCode.Focus();
SendKeys.SendWait("{Delete}");
}
}
AccessCode控件还具有一个Leave事件,用于检查有效数据.
The AccessCode control also had a Leave event that checked for valid data.
这篇关于清除NumericUpDown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!