A simple question : How to enable/disable a button at runtime

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 21
Reputation: hkBattousai is an unknown quantity at this point 
Solved Threads: 0
hkBattousai's Avatar
hkBattousai hkBattousai is offline Offline
Newbie Poster

A simple question : How to enable/disable a button at runtime

 
0
  #1
Feb 9th, 2007
I have two buttons in my main window frame, named btStart and btStop. btStop is initially disabled.
I want to write down such a code that ,
-when user clicks btStart, btStart will be disabled and btStop will be enabled,
-when user clicks btStop, btStop will be disabled and btStart will be enabled.

How can I do that?
Last edited by hkBattousai; Feb 9th, 2007 at 5:40 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,515
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1480
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: A simple question : How to enable/disable a button at runtime

 
0
  #2
Feb 9th, 2007
why not just have one button and toggle its title between start and stop. Inside the button's event handler get the button's text, if its start change it to stop and do the start function, otherwise if its stop change it to start and do the stop function.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 173
Reputation: RwCC is an unknown quantity at this point 
Solved Threads: 4
RwCC's Avatar
RwCC RwCC is offline Offline
Junior Poster

Re: A simple question : How to enable/disable a button at runtime

 
1
  #3
Feb 9th, 2007
Hi hkBattousai

Very easy to do that. Here is the code, it will do what you want it to:

  1. private void btStart_Click(object sender, EventArgs e)
  2. {
  3. btStart.Enabled = false;
  4. btStop.Enabled = true;
  5.  
  6. }
  7.  
  8. private void btStop_Click(object sender, EventArgs e)
  9. {
  10. btStart.Enabled = true;
  11. btStop.Enabled = false;
  12. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 21
Reputation: hkBattousai is an unknown quantity at this point 
Solved Threads: 0
hkBattousai's Avatar
hkBattousai hkBattousai is offline Offline
Newbie Poster

Re: A simple question : How to enable/disable a button at runtime

 
0
  #4
Feb 9th, 2007
Originally Posted by Ancient Dragon View Post
why not just have one button and toggle its title between start and stop. Inside the button's event handler get the button's text, if its start change it to stop and do the start function, otherwise if its stop change it to start and do the stop function.
Thank you for your reply.
Your solution indeed is a good alternative. But I want to learn how to disable and enable a control.

I am new at C#, I don't believe it would be so difficult to implement. Before C# I was using Win32. Enabling/Disabling controls was done with just one function, like this :
  1. EnableWindow(hWnd, TRUE);
  2. // or
  3. EnableWindow(hWnd, FALSE);
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 173
Reputation: RwCC is an unknown quantity at this point 
Solved Threads: 4
RwCC's Avatar
RwCC RwCC is offline Offline
Junior Poster

Re: A simple question : How to enable/disable a button at runtime

 
0
  #5
Feb 9th, 2007
Originally Posted by hkBattousai View Post
Thank you for your reply.
Your solution indeed is a good alternative. But I want to learn how to disable and enable a control.

I am new at C#, I don't believe it would be so difficult to implement. Before C# I was using Win32. Enabling/Disabling controls was done with just one function, like this :
  1. EnableWindow(hWnd, TRUE);
  2. // or
  3. EnableWindow(hWnd, FALSE);

If you check my post you will see the code to easily enable/disable the buttons based on which you click.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 21
Reputation: hkBattousai is an unknown quantity at this point 
Solved Threads: 0
hkBattousai's Avatar
hkBattousai hkBattousai is offline Offline
Newbie Poster

Re: A simple question : How to enable/disable a button at runtime

 
0
  #6
Feb 9th, 2007
Oh, sorry. I didn't scroll down the page then...
Thank you.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: BTD is an unknown quantity at this point 
Solved Threads: 0
BTD BTD is offline Offline
Newbie Poster
 
0
  #7
Oct 14th, 2009
Actually I want to disable an InfoPath 2007 button when a user clicks a radio button on my infoPath form.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 2
Reputation: suganyavasudev is an unknown quantity at this point 
Solved Threads: 0
suganyavasudev suganyavasudev is offline Offline
Newbie Poster
 
0
  #8
Oct 14th, 2009
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ex1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
stop.Visible = false;
}

private void start_Click(object sender, EventArgs e)
{

stop.Visible = true;
start.Visible = false;
}

private void stop_Click(object sender, EventArgs e)
{
start.Visible = true;
stop.Visible = false;
}
}
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 2
Reputation: suganyavasudev is an unknown quantity at this point 
Solved Threads: 0
suganyavasudev suganyavasudev is offline Offline
Newbie Poster
 
0
  #9
Oct 14th, 2009
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ex1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
stop.Visible = false;
}

private void start_Click(object sender, EventArgs e)
{

stop.Visible = true;
start.Visible = false;
}

private void stop_Click(object sender, EventArgs e)
{
start.Visible = true;
stop.Visible = false;
}
}
}
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC