| | |
A simple question : How to enable/disable a button at runtime
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
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?
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.
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.
Hi hkBattousai
Very easy to do that. Here is the code, it will do what you want it to:
Very easy to do that. Here is the code, it will do what you want it to:
c# Syntax (Toggle Plain Text)
private void btStart_Click(object sender, EventArgs e) { btStart.Enabled = false; btStop.Enabled = true; } private void btStop_Click(object sender, EventArgs e) { btStart.Enabled = true; btStop.Enabled = false; }
•
•
•
•
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.
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 :
C# Syntax (Toggle Plain Text)
EnableWindow(hWnd, TRUE); // or EnableWindow(hWnd, FALSE);
•
•
•
•
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 :
C# Syntax (Toggle Plain Text)
EnableWindow(hWnd, TRUE); // or EnableWindow(hWnd, FALSE);
If you check my post you will see the code to easily enable/disable the buttons based on which you click.
•
•
Join Date: Jun 2009
Posts: 2
Reputation:
Solved Threads: 0
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;
}
}
}
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;
}
}
}
•
•
Join Date: Jun 2009
Posts: 2
Reputation:
Solved Threads: 0
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;
}
}
}
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;
}
}
}
![]() |
Similar Threads
- How to Enable/Disable Users thro' C++ or any code (C++)
- How to enable or disable Internet Explorer tool bar buttons using javascript (JavaScript / DHTML / AJAX)
- This has to be a simple question to answer. (Visual Basic 4 / 5 / 6)
- HELP! No Advanced to enable/disable CTRL (Windows NT / 2000 / XP)
Other Threads in the C# Forum
- Previous Thread: InfoPath Question
- Next Thread: Capture Toshiba Mute, Lights Off and Dolby Key
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database databasesearch datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files focus form format forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot math mouseclick mysql networking object operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






