Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a button named start. Now once I press start, the application runs fine..

I need to do like this:once the application reaches a particular point it should return to the previous form(first form which is having start button).And there now the button should be stop instead of start.

Can I do like that in C# windows application?If so, how?

Please do help me on this..

Thanks..
Posted

1 solution

Here are two options to get you started

Option 1:
Keep the start button as is, place the Stop button next to it. You can use the Visible property on each to decide which is displayed (the stop button should have this as false by default). You could alternatively use the Enabled property, the disabled button will appear greyed out.


Option 2:
Just change the Text property of the existing button as required. Remember to rename the button if you have called it btnStart. Obviously you'll need to sort the extra logic to determine whether the button is Starting or Stopping. A quick hack approach would be to even use the button Text, though hopefully the rest of your code is well enough designed to make this unnecessary.

[Edit]
In response to OP's comment: Assuming the button is called btnStart for example, in code you do the following:

C#
btnStart.Visible = true; //To display, false to hide obviously


As for hiding the Stop button, click on it in the designer window in Visual Studio. In the properties tab, find the "Visible" property in the list and set the value to false in that. If you are having problems finding the property tab, right click the button and choose "Properties", the tab is docked to the right on a default setup.
 
Share this answer
 
v2
Comments
Vysakh Venugopal 6-Jun-13 7:23am    
@keith Barrow: Thanks..If Iam opting 1,then can I make stop button visible and start button invisible??If so,how?
Keith Barrow 6-Jun-13 7:59am    
HI, I've updated my answer.
Vysakh Venugopal 6-Jun-13 8:38am    
@keith barrow: thanks keith..thats working!!!I went with Option 2..

Can I ask you one more doubt..I have changed my button name now at a point of my app.Now When I click the button with the new name,I should be able to do some other function..Could you please help me on how I can achieve that??
Keith Barrow 6-Jun-13 8:42am    
You need to put an if statement in the Event handler, a ***hack** answer is:
if(btnStart.Text=="Start")
{
CallStartMethod();
}
else
{
CallStopMethod();
}

But you should find a solution that is cleaner, by either keeping track of whether the state is running separately, or doing this on the object you are running the long=lived process on.
Vysakh Venugopal 6-Jun-13 8:50am    
@Keith Barrow: Ok...I have a label that is hidden(visible property set to false).How can I achieve when a button is clicked that label is visible.??

I just tried your btnStart.Visible = true;

But sorry..Its not working..

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