Reputation: 241
I am writing an add-on for visual studio that includes two buttons. I want that when the user hits one of them, this button will be disabled and the another one will be enabled. How can I do it?
The buttons are Command type (commands.AddNamedCommand2
...)
Upvotes: 1
Views: 20776
Reputation: 37
Furthermore If you want to enable or disable those buttons in their initial status.As an example you want to disable button1 in the program.After stating program you want to enable button1 after clicking button2,then You want to add button status on page loading as follows;
private void Form1_Load(object sender, EventArgs e)
{
this.button1.Enabled = false;
this.button2.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
this.button1.Enabled = true;
}
Upvotes: 0
Reputation: 878
You can associate some state variable with your buttons wich can express whether your button should be enabled in the recent state of your Add-In. When your Add-In itinializes, you should set the state as you whish. In the query you can check the recent state of your Add-In and set the buttuns into their proper enabled / unsupported state.
The state can be modified through the QueryStatus
method of the IDTCommandTarget
interface (If your Add-In is loaded).
Default template implementation:
public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
{
if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
{
if(commandName == "YourAddin.Connect.YourAddinCommandName")
{
status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
return;
}
}
}
You can disable a button by setting the status to vsCommandStatus.vsCommandStatusUnsupported
Upvotes: 0
Reputation: 1
// Remove event handler
this.button_Ping.Click -= new System.EventHandler(this.button_Ping_Click);
Some action...
// Add event handler
this.button_Ping.Click += new System.EventHandler(this.button_Ping_Click);
Upvotes: -1
Reputation: 1583
You can try this:
private void button1_Click(object sender, EventArgs e)
{
this.button1.Enabled = false;
this.button2.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
this.button2.Enabled = false;
this.button1.Enabled = true;
}
Hope this will help you....
Upvotes: 1
Reputation: 29000
void Btn1_Click(Object sender, EventArgs e)
{
Btn2.Enabled = false;
}
void Btn2_Click(Object sender, EventArgs e)
{
Btn1.Enabled = false;
}
Upvotes: 1