2
Answers

Increment manually...

Israel

Israel

10y
716
1
Hello!
 
I have on my form: two button (one for "Add" and other one for "Minus"), one label that will have always the number "1" and one textbox that will have the number 0 in load the form (its can be changed only when I click on one of the button "add" or "minus").
 
I wrote this code to increment manually step by step one number. For example: if in my textbox content 0 when I click my button its will add "1". When you click again its will add "1" (in textbox will appear "2"). Means 1 plus 1 plus 1 plus 1 plus 1 plus 1 etc.
Then when I click to the minus button its make substration. Until there every think it's ok. But what I need now: I want when I click on the minus button its cannot do this "-1". The only CONDITION is its cannot descrease number (the limit it's "0" never negative number):
 
This increase and working well:
 
private void btnplus_consStocks_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(lblIncrement.Text))
{
return;
}
double increment1;
double increment2;
double resultincrement;
increment1 = Convert.ToDouble(lblIncrement.Text);
increment2 = Convert.ToDouble(stockLimitadoUpDown1.Text);
resultincrement = increment1 + increment2;
stockLimitadoUpDown1.Text = resultincrement.ToString();
}
 
 
But this its decrease well but when its arrive to "0" when you click again its show "-1" as I already explain:
 
private void btnmenos_consStocks_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(lblIncrement.Text))
{
return;
}
double increment1;
double increment2;
double resultincrement;
increment1 = Convert.ToDouble(lblIncrement.Text);
increment2 = Convert.ToDouble(stockLimitadoUpDown1.Text);
resultincrement = increment2 - increment1;
stockLimitadoUpDown1.Text = resultincrement.ToString();
}
 
 
 
Answers (2)