Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Please help me out to find the answer of my question.
.Net code for Changing the values in the Label according to the buttons Next, Previous , Last and First. The value of Label must be between 1 to 20.
Posted
Comments
Sandeep Mewara 23-May-12 10:51am    
And the issue is?

Just use the counter.
By clicking on the "Next" increases by one.
By clicking on the "back" button, reduces it to one.

Each time you press a button after changing the value of counter, you should assigning his value to the property "text" of the button

For example:
C#
private int counter;

private void btnNext_Click(object sender, EventArgs e)
{
           counter++;
           if(counter < 21 && counter > 0 )
           {
             myLabel.Text = counter.ToStreing();
           }
}

private void btnBack_Click(object sender, EventArgs e)
{
         counter--;
         if(counter < 21 && counter > 0 )
         {
             myLabel.Text = counter.ToStreing();
         }
}


Of course you can use a function,for example SetLabel, and call it from both places .....

Regards,
Alex.
 
Share this answer
 
v2
For Last and First it is simple

on Last click set label.text = 20

on First click set label.text = 1

On Next Click first, Get text from label and convert it into integer and increment by one and set it to label again.


On Previous Click first, Get text from label and convert it into integer and decrement by one and set it to label again.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900