Adding ADXCommandBarButtons at runtime

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

Adding ADXCommandBarButtons at runtime
 
Ryan Farley




Posts: 109
Joined: 2005-04-28
In my addin, I would like to store the definitions of the buttons in the addin in a database and then create them at runtime.

I have this almost working, except it is just not quite right. The newly added button is there, but it just doesn't show. If I cause a MessageBox to fire then the button shows (once the MessageBox has been closed). From that point all is well and the button works fine.

The code to add the button is simple enough:

ADXCommandBarButton button = new ADXCommandBarButton();
button.Caption = "Some button 1";
button.ControlTag = new Guid("dddddddd-dddd-dddd-dddd-dddddddddddd").ToString();
button.Style = ADXMsoButtonStyle.adxMsoButtonCaption;
button.Temporary = true;
button.UpdateCounter = 10;
button.Click += new ADXClick_EventHandler(this.buttonGeneric_Click);

adxOlExplorerCommandBar1.Controls.Add(button);


Like I said, the button is there, just doesn't show until something else happens. Is there some way I can invalidate the addin to cause it to repaint or something? Know what I mean?
Posted 07 Jun, 2006 02:06:10 Top
Matt Driver


Matt


Posts: 152
Joined: 2004-08-17
Hi

I used to have a similar issue what I actually did in the end was to chance the width of a button by one pixel and then put it back so:

button.width = button.width - 1;
button.width = button.width + 1;

give it a go.

Matt
Posted 07 Jun, 2006 04:47:03 Top
Sergey Grischenko


Add-in Express team


Posts: 7228
Joined: 2004-07-05
Hi Ryan, Matt.

Please download and try the following example:
http://www.add-in-express.com/projects/dynamiccontrolsexample.zip





Posted 07 Jun, 2006 11:09:48 Top
Ryan Farley




Posts: 109
Joined: 2005-04-28
Thanks guys,

Using the sample code I posted before, here's what changed for it to work:

ADXCommandBarControl ctrl = adxOlExplorerCommandBar1.Controls.Add(
typeof(ADXCommandBarButton),
new Guid("dddddddd-dddd-dddd-dddd-dddddddddddd").ToString(),
1,
0,
true);

ADXCommandBarButton button = ctrl.AsButton;
button.Caption = "Some button 1";
button.Style = ADXMsoButtonStyle.adxMsoButtonCaption;
button.Temporary = true;
button.UpdateCounter = 10;
button.Click += new ADXClick_EventHandler(this.buttonGeneric_Click);


Basically, added to the container first, then set the properties of the returned control.

All good now. Thanks.
Posted 07 Jun, 2006 15:13:47 Top