I’ve got a NumericUpDown control, and I want the value inside a seperate textbox to decrease or increase depending on which input the user inputes (up or down)
What event or code do I use to accomplish this?
I tried this but got an error while running
“Unable to cast object of type ‘System.Windows.Forms.NumericUpDown’ to type ‘System.IConvertible’.
int UpDownNum;
int NumBank;
int TV = 0
private void UpDown1_MouseUp(object sender, MouseEventArgs e)
{
UpDownNum = (Convert.ToInt32(UpDown1));
NumBank = (Convert.ToInt32(NumTextbox.Text));
TV = NumBank - UpDownNum;
NumTextbox.Text = (Convert.ToString(TV));
Am I doing the wrong event? or is it some other problem?
The exception is caused by casting the
NumericUpdowncontrol to an integer. That doesn’t work. You need to use theNumericUpdown.Valueproperty.I assume that it’s the
ValueChangedevent that you’re looking for:Edit:
The only way i know to get the difference between the old and the new value of a
NumericUpDownvalue is to save the old value manually(for example in a member variable) and change it in ValueChanged after you’ve calculated the difference (see edited code above).