Adding buttons at run-time

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

Adding buttons at run-time
 
Artur Nowocin




Posts: 16
Joined: 2007-02-15
I was trying to add new button at runtime. Right now I'm getting aquainted with add-in express so I'm doing weird, easy things, but this one won't work. I want to add new button when I press another one.

private void adxCommandBarButton1InMyManu_Click(object sender)
{
AddinExpress.MSO.ADXCommandBarButton adxCommandBarButton1;
adxCommandBarButton1 = new AddinExpress.MSO.ADXCommandBarButton(this.components);
			
adxCommandBarButton1.Caption = "New button";
adxCommandBarButton1.ControlTag = "6addfdad-d5ef-4b13-870a-bfe7084bc233";[I]//do I have to set ControlTag?[/I]
adxCommandBarButton1.ImageTransparentColor = System.Drawing.Color.Transparent;
adxCommandBarButton1.Visible = true; [I]//I think not obligatory[/I]
adxCommandBarButton1.ImageTransparentColor = System.Drawing.Color.Transparent;[I]//I think not obligatory[/I]
adxCommandBarButton1.AfterID = 1;[I]//I think not obligatory[/I]
System.Windows.Forms.MessageBox.Show("With button " + ((AddinExpress.MSO.ADXCommandBarButton)sender).Caption + " I add button "+
 adxCommandBarButton1.Caption); [I]//don't care about those messages[/I]
adxCommandBarPopup3.Controls.Add(adxCommandBarButton1);			System.Windows.Forms.MessageBox.Show(adxCommandBarPopup3.Controls.Contains(adxCommandBarButton1).ToString());
[I]//I was checking if control was added and it was[/I]
adxCommandBarPopup3.Controls.Remove(adxCommandBarButton2InMyManu);
[I]//It works, button defined in design mode can be removed[/I]
System.Windows.Forms.MessageBox.Show(adxCommandBarButton1.Caption);
//another stupid MessageBox ;-)
}

Am I missing something?
Posted 16 Feb, 2007 08:43:29 Top
Artur Nowocin




Posts: 16
Joined: 2007-02-15
I search the forum and found some thread about dynamic controls. I modified my code with following:

			AddinExpress.MSO.ADXCommandBarControl ctrl = adxCommandBarPopup3.Controls.Add(
				typeof(AddinExpress.MSO.ADXCommandBarButton),new Guid("6addfdad-d5ef-4b13-870a-bfe7084bc233").ToString(),1,0,true); ;
			AddinExpress.MSO.ADXCommandBarButton button = ctrl.AsButton;
			button.Caption = "New button";
			button.ImageTransparentColor = System.Drawing.Color.Transparent;
			button.Visible = true;			
			System.Windows.Forms.MessageBox.Show("With button " + ((AddinExpress.MSO.ADXCommandBarButton)sender).Caption + " I add button ""+
				 button.Caption + """);

It works, but I'm still confused 'cause I don't know what's wrong with previous one and what I am missing.

Additionally I found an example "dynamiccontrolsexample.zip" but there's something missing. I don't have GetControlByControlTag method for AddinExpress.MSO.ADXBaseControlCollection object. So example doesn't work. Contrary I do have this method for AddinExpress.MSO.ADXCommandBarControlCollection. Are there any examples for my Add-in Express version. I think we have Add-in Express .NET Version 2.2 Build 1751.
Posted 16 Feb, 2007 09:25:16 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Artur,

The fact is that the example is built using the latest versions of the Add-in Express 2007 product. Please upgrade the product up to v3.3.

The code in the first post didn't work because it was designed for the design time only. However you can also use this code in the AddinInitialize event handler.


P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
Posted 16 Feb, 2007 13:51:24 Top
Artur Nowocin




Posts: 16
Joined: 2007-02-15
How can I update Add-in Express? Do you mean buy newest version?
Posted 19 Feb, 2007 09:53:24 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Artur,

Do you mean buy newest version?

Yes.

Please send me a private e-mail using the link at the left of this message and I will help you with upgrading.

Andrei Smolin
Add-in Express Team Leader
Posted 19 Feb, 2007 10:42:07 Top