Changing the icon for an ADXCommandBarButton

Add-in Express™ Support Service
That's what is more important than anything else

Changing the icon for an ADXCommandBarButton
 
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
How do you change the icon of a button in a CommandBar at runtime?

I tried something like this to no avail (the code below is switching the State property of the button when the user clicks on it):
...
AddinExpress.MSO.ADXCommandBarButton btnSender =
sender as AddinExpress.MSO.ADXCommandBarButton;

// switch state
bool bIsActive = !(btnSender.State ==
AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonDown);
btnSender.State = bEmail2Active ?
AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonDown :
AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonUp;

// now the image
btnSender.Image = bIsActive ? 3 : 2;
...

In a non-ADX context I would do this by accessing the "Picture" property of the Microsoft.Office.Core.CommandBarButton object and assign to it a bitmap loaded from the registry.

I think I should be able to the same with my buytton (accessing the ControlObj property of the ADXCommandBarButton object), but it seems totally redundant considering that I have already loaded those images at design time.

What would be the way to do this taking advantage of the design-time features provided by ADX?

Thanks in advance!
Posted 18 Mar, 2006 16:44:47 Top
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
I forgot to mention that the code above works fine for an Explorer's command bar button. It's only in an Inspector command bar button that it doesn't change the image. Which makes the whole thing even more weird

;)

Thanks.
Posted 18 Mar, 2006 21:30:29 Top
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
I found something else. As I said before I can make this code to work on an Explorer’s toolbar button.

I have just found out that I can also make it to work on an Inspector’s toolbar button but only when I’m opening an existing email item. If I create a new message the above code doesn’t work. The image refuses to change.

It is interesting though that in this case (editing a new mail message in an Inspector window) when I right click the toolbar’s area I don’t have access to the “Customize” option, whereas in the other two cases (Explorer and existing mail item in Inspector) the option is available.

Could be the reason for this problem? In that case, does anyone know how to get around that problem?

Posted 20 Mar, 2006 16:23:52 Top
Sergey Grischenko


Add-in Express team


Posts: 7235
Joined: 2004-07-05
Hi Esteban.

I have just tested dynamic images on a button in an Inpector window.
It works fine for a new email as well as for an existing one. Please look at the code below. Probably I do something differently.

private void adxCommandBarButton1_Click(object sender)
{
if (adxCommandBarButton1.State == AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonUp)
{
adxCommandBarButton1.State = AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonDown;
adxCommandBarButton1.Image = 1;
}
else
{
adxCommandBarButton1.State = AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonUp;
adxCommandBarButton1.Image = 0;
}
}
Posted 20 Mar, 2006 16:50:49 Top
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
That is so weird because I'm using exactly the same code you are using!

I will create a new toolbar from scratch just in case I changed something accidentaly. Also, I jsut realized that I'm using Word as email editor. COuld this be the reason? I will test both and post my results here in a moment

Thanks
Posted 20 Mar, 2006 17:13:23 Top
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
It's the Word editor!

If I disable Word as the email editor and open an Inspector with a new message the icon changes as expected.

Of course, I cannot tell my users that they are not allowed to use Word as the email editor

Any ideas on how to get around this problem?

Posted 20 Mar, 2006 17:18:38 Top
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
This is really strange. If I use the code you suggested:

private void adxCommandBarButton1_Click(object sender)
{
if (adxCommandBarButton1.State == AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonUp)
{
adxCommandBarButton1.State = AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonDown;
adxCommandBarButton1.Image = 1;
}
else
{
adxCommandBarButton1.State = AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonUp;
adxCommandBarButton1.Image = 0;
}
}

Only the image is not updated when Word is the email editor. The State property is correctly updated in both cases (using Word or not as the editor)

Why the difference?
Posted 20 Mar, 2006 17:43:30 Top
Sergey Grischenko


Add-in Express team


Posts: 7235
Joined: 2004-07-05
Ok. I will test it and will send you an email soon.
Posted 20 Mar, 2006 18:05:02 Top
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
Thank you Sergey!

Looking forward to your email..
Posted 20 Mar, 2006 18:06:54 Top