Hello Dave,
Based on my understanding, you are looking for a method to show a custom
popup menu in Excel. As AMercer said, ContextMenuStrip might be a
resolution because it does not need a parent handle. Please have a try to
see if it fits your request. From the view of Excel, another possible
workaround is to customize the built-in popup menu when we right-click on a
worksheet cell. Here is an example:
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
applicationObject =
(Excel.Application)application;
applicationObject.SheetBeforeRightClick += new
Excel.AppEvents_SheetBeforeRightClickEventHandler(applicationObject_SheetBef
oreRightClick);
addInInstance = addInInst;
}
void applicationObject_SheetBeforeRightClick(object Sh,
Microsoft.Office.Interop.Excel.Range Target, ref bool Cancel)
{
CommandBar cellbar = applicationObject.CommandBars["Cell"];
CommandBarButton button =
(CommandBarButton)cellbar.FindControl(MsoControlType.msoControlButton, 0,
"MYMENU", missing, missing);
if (button == null)
{
// add the button
button =
(CommandBarButton)cellbar.Controls.Add(MsoControlType.msoControlButton,
missing, missing, cellbar.Controls.Count + 1, true);
button.Caption = "My Menu";
button.BeginGroup = true;
button.Tag = "MYMENU";
button.Click += new
_CommandBarButtonEvents_ClickEventHandler(button_Click);
}
}
void button_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
MessageBox.Show("Test");
}
The example register the SheetBeforeRightClick event. In the event handler,
we check if the custom button has already been added to the popup menu. If
not, we add the button by calling CommandBar.Controls.Add method. After we
install the add-in, it shows a custom button "My Menu" at the bottom of
right-click popup menu, and shows a "Text" message box when we click on it.
If you have any other concern or need anything else, please feel free to
let me know.
Regards,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.