How do you Enable/Disable tool within a toolbar programmatically?

2613
1
Jump to solution
10-25-2012 08:03 AM
GenaroGarcia
New Contributor III
I have custom tools in a custom toolbar which one of them I need to disable when click on.
This tool invokes a custom entry form which I need to enable to tool when the form closes.

Is there a way to do this?

Any advice would be greatly appreciated.
0 Kudos
1 Solution

Accepted Solutions
RichWawrzonek
Occasional Contributor
Genaro-
Is your custom toolbar an Add-In or a COM extension?

For an Add-In you need to add the OnUpdate() method to the main tool class:
protected override void OnUpdate()
        {
            Enabled = true;   //Change this to evaluate a statement instead of always returning true
        }


For a COM tool you add the Enabled() method:
public override bool Enabled
        {
            get
            {
                return true;   //Change this to evaluate a statement instead of always returning true
            }
        }


Note that these methods are continuously called by ArcMap so don't call any methods that take much time here. If your form is a singleton then you can simply do something like this:

Enabled = frmMyForm.OnlyInstance != null && frmMyForm.OnlyInstance.Visible; 

View solution in original post

0 Kudos
1 Reply
RichWawrzonek
Occasional Contributor
Genaro-
Is your custom toolbar an Add-In or a COM extension?

For an Add-In you need to add the OnUpdate() method to the main tool class:
protected override void OnUpdate()
        {
            Enabled = true;   //Change this to evaluate a statement instead of always returning true
        }


For a COM tool you add the Enabled() method:
public override bool Enabled
        {
            get
            {
                return true;   //Change this to evaluate a statement instead of always returning true
            }
        }


Note that these methods are continuously called by ArcMap so don't call any methods that take much time here. If your form is a singleton then you can simply do something like this:

Enabled = frmMyForm.OnlyInstance != null && frmMyForm.OnlyInstance.Visible; 
0 Kudos