Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Custum Excel RMB Context Menu

Hi Nick,

It seems to be hard to implement it via the winform context menu.
I think we would better do it by change the default cell contextmenu, i.e.
the menu which will be shown when we right click on the sheet.
Here goes the code snippet.

<Code snippet
public ContextMenu m_RMBContextMenu = null;
Excel.Application exApp=null;
Microsoft.Office.Core.CommandBarButton cbb=null;
Microsoft.Office.Core.CommandBar t=null;

public void NewWorkbook(Excel.Workbook Wb)
{
System.Diagnostics.Debug.WriteLine("NewWorkbook");
exApp = Wb.Application;
object type = 1;
object oMissing = System.Reflection.Missing.Value;
//find the cell menu and then disable all and then add the ones we want
int cnt =
(int)exApp.CommandBars.GetType().InvokeMember("Cou nt",System.Reflection.Bind
ingFlags.GetProperty,null,exApp.CommandBars,new object[]{});
for( int i =1 ;i<=cnt;i++)
{
t =
(Microsoft.Office.Core.CommandBar)exApp.GetType(). InvokeMember("CommandBars"
,System.Reflection.BindingFlags.GetProperty,null,e xApp,new object[]{i});
if (t.Name == "Cell")
{
t.Reset();
for(int j =1;j<=t.Controls.Count;j++)
t.Controls[j].Visible = false;
cbb =
(Microsoft.Office.Core.CommandBarButton)t.Controls .Add(type,oMissing,oMissin
g,oMissing,oMissing);
break;
}
}
cbb.Caption = "Hello";
cbb.Click+=new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(cbb_Click);
}

private void cbb_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref
bool CancelDefault)
{
Console.WriteLine("cbb_Click");
}

public void WorkbookBeforeClose(Excel.Workbook Wb, ref bool Cancel)
{
t.Reset(); //reset the menu
System.Diagnostics.Debug.WriteLine("WorkbookBefore Close");
}
<Code snippet

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding commands to the Excel 2007 Chart context menu Andreas Charts and Charting in Excel 1 January 23rd 09 08:15 PM
Excel 2003 Context menu handle [email protected] Excel Discussion (Misc queries) 3 June 4th 07 02:48 PM
Updating context menu in Excel Tim879 Excel Discussion (Misc queries) 0 February 28th 07 08:42 PM
Add items to context menu Fred Jacobowitz Excel Worksheet Functions 1 April 22nd 06 10:29 PM
context menu eric23 Excel Programming 3 May 9th 04 11:49 PM


All times are GMT +1. The time now is 12:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"