Clearing NumericUpDown

前端 未结 3 1190
别那么骄傲
别那么骄傲 2021-01-29 12:39

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 c

3条回答
  •  伪装坚强ぢ
    2021-01-29 12:59

    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.

    This hid the NumericUpDown control spinners.

    AccessCode.Controls[0].Visible = false;
    

    These statements were in the form initialization. (var code was to be loaded into AccessCode)

            if (code == 0)
            {
                AccessCode.ForeColor = Color.White;
            }
    

    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}");
            }
        }
    

    The AccessCode control also had a Leave event that checked for valid data.

提交回复
热议问题