V
Vaelek
I am developing a shared addin for Outlook 2003 with VS2005 in C#.
I have created wrapper functions to create a commandbar, commandbarpopup,
and commandbarbuttons. Initially the relative CommandBar* objects were
defined both at the class level, and within the functions that added the new
ones, which simply returned the created object which was then assigned to the
global object. This seemed to work but my events would stop firing after a
few minutes.
After searching for a while I found that the objects must be declared at the
class level so I moved my temporary object declarations there as well. My
problem now is this: The only event that fires is the one attatched to the
last CommandBarButton added. I am reusing a global object to add the items
and I suspect this is where the problem is coming from.
My globals are:
//These 2 are used repeatedly during item creation
private CommandBarPopup SubMenu;
private CommandBarButton MenuItem;
//These 2 are used within the wrapper functions
private CommandBarControl _item;
private CommandBarControl _popup;
my functions look like this:
private CommandBarPopup AddPopupMenu(string Caption, CommandBarControl
_parent)
{
object mis = Missing.Value;
_popup = (_parent as
CommandBarPopup).Controls.Add(MsoControlType.msoControlPopup, mis, mis, mis,
true);
_popup.Caption = Caption;
return (_popup as CommandBarPopup);
}
private CommandBarControl AddMenuItem(string Caption, CommandBarPopup _parent)
{
object mis = Missing.Value;
_item = _parent.Controls.Add(MsoControlType.msoControlButton, mis, mis,
mis, true);
_item.Caption = Caption;
return _item;
}
I build the menu as such
SubMenu = AddPopupMenu("This is a popup menu");
SubMenu = AddPopupMenu("This is a submenu");
MenuItem = (CommandBarButton)AddMenuItem("Menu Item");
MenuItem.Click += EventMethod1
MenuItem = (CommandBarButton)AddMenuItem("Another Item");
MenuItem.Click += EventMethod2
There is a little more going on as I have the appropriate parents tracked in
overrides of the above functions, but that is not the issue, what is above
works with what I have. The problem, is that given the above code,
EventMethod1 will never be executed. EventMethod2 will work just fine.
What do I have to do to be able to build the menus in this fashion? I
absolutely do *NOT* want to have to create an object to hold each and every
item as it is generated dynamically.
HELP!
THANKS!
I have created wrapper functions to create a commandbar, commandbarpopup,
and commandbarbuttons. Initially the relative CommandBar* objects were
defined both at the class level, and within the functions that added the new
ones, which simply returned the created object which was then assigned to the
global object. This seemed to work but my events would stop firing after a
few minutes.
After searching for a while I found that the objects must be declared at the
class level so I moved my temporary object declarations there as well. My
problem now is this: The only event that fires is the one attatched to the
last CommandBarButton added. I am reusing a global object to add the items
and I suspect this is where the problem is coming from.
My globals are:
//These 2 are used repeatedly during item creation
private CommandBarPopup SubMenu;
private CommandBarButton MenuItem;
//These 2 are used within the wrapper functions
private CommandBarControl _item;
private CommandBarControl _popup;
my functions look like this:
private CommandBarPopup AddPopupMenu(string Caption, CommandBarControl
_parent)
{
object mis = Missing.Value;
_popup = (_parent as
CommandBarPopup).Controls.Add(MsoControlType.msoControlPopup, mis, mis, mis,
true);
_popup.Caption = Caption;
return (_popup as CommandBarPopup);
}
private CommandBarControl AddMenuItem(string Caption, CommandBarPopup _parent)
{
object mis = Missing.Value;
_item = _parent.Controls.Add(MsoControlType.msoControlButton, mis, mis,
mis, true);
_item.Caption = Caption;
return _item;
}
I build the menu as such
SubMenu = AddPopupMenu("This is a popup menu");
SubMenu = AddPopupMenu("This is a submenu");
MenuItem = (CommandBarButton)AddMenuItem("Menu Item");
MenuItem.Click += EventMethod1
MenuItem = (CommandBarButton)AddMenuItem("Another Item");
MenuItem.Click += EventMethod2
There is a little more going on as I have the appropriate parents tracked in
overrides of the above functions, but that is not the issue, what is above
works with what I have. The problem, is that given the above code,
EventMethod1 will never be executed. EventMethod2 will work just fine.
What do I have to do to be able to build the menus in this fashion? I
absolutely do *NOT* want to have to create an object to hold each and every
item as it is generated dynamically.
HELP!
THANKS!