NumericUpDown is control that looks like TextBox. This control allow user to display/select number from a range. Up and Down arrows are updating the textbox value.
Control look like;
In Form_Load
range can be set.
private void Form3_Load(object sender, EventArgs e)
{
numericUpDown1.Maximum = 10;
numericUpDown1.Minimum = -10;
}
Output;
UpDownAlign will set the position of arrows;
private void Form3_Load(object sender, EventArgs e)
{
numericUpDown1.UpDownAlign = LeftRightAlignment.Left;
}
Output;
UpButton()
Method increase the number of the control. (can be called from anywhere. I used a button
to call it.)
private void button1_Click(object sender, EventArgs e)
{
numericUpDown1.UpButton();
}
**Output
DownButton()
Method decrease the number of the control. (can be called from anywhere. I used a button
to call it again.)
private void button2_Click(object sender, EventArgs e)
{
numericUpDown1.DownButton();
}
Output;
ValueChanged;
That event will work when Up or Down arrow clicked.
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
decimal result = numericUpDown1.Value; // it will get the current value
if (result == numericUpDown1.Maximum) // if value equals Maximum value that we set in Form_Load.
{
label1.Text = result.ToString() + " MAX!"; // it will add "MAX" at the end of the label
}
else if (result == numericUpDown1.Minimum) // if value equals Minimum value that we set in Form_Load.
{
label1.Text = result.ToString() + " MIN!"; // it will add "MIN" at the end of the label
}
else
{
label1.Text = result.ToString(); // If Not Max or Min, it will show only the number.
}
}
Output;