Michael Gatzonis
Guest
|
I have a Add-on which declares a Module, a Toolbar and a Sidebar as
MyNamespace.MyModule
MyNamespace.MySideBar with name adxieBarItem1
MyNameSpace.MyToolbar with name adxieToolBarItem1
I want to change a sidebar's control property (e.g. textbox1) when a button (e.g.Button1) on MyToolbar is clicked.
Here is the code I use (C#). Although this works I wonder if there is a better way to do it.
1. MyToolbar Code
private void onButton1_Click(object sender, EventArgs e)
{
MyNameSpace.MyModule theModule = (MyNameSpace.MyModule) this.Module;
for (int i = 0; i <= theModule.GetModuleCount() - 1; i++)
{
MyNameSpace.MyModule aModule = (MyNameSpace.MyModule) theModule.GetModuleByIndex(i);
if (aModule.IsTabActive()) //find active tab
{
aModule.ChangeProperty(newValue); //Call a public method of MyModule
}
}
}
2. MyModule Code
public void ChangeProperty(String newValue)
{
MyNameSpace.MySideBar mybar = (MyNameSpace.MySideBar) adxieBarItem1.BarObj;
if (mybar != null) //Check if sidebar is loaded
{
mybar.ChangeProperty(newValue); //call a public method of MySideBar
}
}
3. MySideBar Code
public void ChangeProperty(String newValue)
{
textbox1.text = newValue;
}
Thanks
Michael |
|
Andrei Smolin
Add-in Express team
Posts: 18823
Joined: 2006-05-11
|
Hi Michael,
Try the following:
1. MyToolbar Code
private void onButton1_Click(object sender, EventArgs e)
{
MyNameSpace.MyModule theModule = (MyNameSpace.MyModule) this.Module;
theModule.ChangeProperty(newValue); //Call a public method of MyModule
}
Andrei Smolin
Add-in Express Team Leader |
|