private void axPivotTable1_BeforeContextMenu(object sender, AxOWC10.IPivotControlEvents_BeforeContextMenuEvent e)
{
Console.WriteLine("右键菜单相应事件");
//生成OWC菜单
object []sub1 = new object[2]{"Red","RED"};
object []sub2 = new object[2]{"Blue","BLUE"};
object SubMenu = new object[2]{"Color",new object[2]{sub1,sub2}};//生成子菜单
object []menu1 = new Object[2]{"Rect","RECT"};
object []menu2 = new Object[2]{"复制",OWC10.OCCommandId.ocCommandCopy.ToString()};
object []menu3 = new Object[2]{"粘贴",OWC10.OCCommandId.ocCommandPaste.ToString()}; //取得原来的菜单
object []MenuValue = (object[])e.menu.Value;

//生成一个新菜单,扩展原来的菜单的数目
object []Temp = new object [MenuValue.Length+5];
//将原菜单中内容复制过来
for(int i=0;i<MenuValue.Length;i++) Temp[i] = MenuValue[i];
//加入新的菜单选项
Temp[MenuValue.Length] =null; //横隔条
Temp[MenuValue.Length+1] = SubMenu;
Temp[MenuValue.Length+2] =menu1;
Temp[MenuValue.Length+3] =menu2;
Temp[MenuValue.Length+4] =menu3;
//方法一:生成新菜单,代替原来的菜单
//object OWCMenu = new Object[4]{SubMenu,menu1,menu2,menu3}; 
//e.menu.Value = OWCMenu;
//方法二:在原来菜单的基础上增加新菜单选项
e.menu.Value = Temp;//改变OWC控件右键菜单


}

/// <summary>
/// 增添的菜单事件处理函数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void axPivotTable1_CommandExecute(object sender, AxOWC10.IPivotControlEvents_CommandExecuteEvent e)
{
Console.WriteLine("右键菜单处理事件");
if(e.command.ToString()!=null)
{
switch(e.command.ToString())
{
case "RED"://处理RED子菜单对应的事件
MessageBox.Show("Show Red","RED");
break;
case "BLUE"://处理Blue子菜单对应的事件
MessageBox.Show("Show Blue","BLUE");
break;
case "RECT"://处理Blue菜单对应的事件
MessageBox.Show("Show Rect","RECT");
break;
case "ocCommandCopy"://调用OWC控件自己的处理复制的事件
axPivotTable1.Commands[OWC10.OCCommandId.ocCommandCopy].Execute();
break;
case "ocCommandPaste"://调用OWC控件自己的处理粘贴的事件
axPivotTable1.Commands[OWC10.OCCommandId.ocCommandPaste].Execute();
break;
}
}
}

/// <summary>
/// 清除原Toolbar中所有Button,重新加入Copy和PasteButton
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
mscomctl.Toolbar tb = axPivotTable1.Toolbar;
//tb.AboutBox();
//清除原Toolbar中所有Button
tb.Buttons.Clear();
//生成新Button,用原Copy button和原Cut Button实现功能
object index =tb.Buttons.Count+1;
object Caption = null;
object Key = "owc"+OWC10.OCCommandId.ocCommandCopy.GetHashCode().ToString();
object Style = mscomctl.ButtonStyleConstants.tbrDefault;
tb.Buttons.Add(ref index,ref Key,ref Caption,ref Style,ref Key);
index =tb.Buttons.Count+1;
Caption = null;
Key = "owc"+OWC10.OCCommandId.ocCommandCut.GetHashCode().ToString();
Style = mscomctl.ButtonStyleConstants.tbrDefault;
tb.Buttons.Add(ref index,ref Key,ref Caption,ref Style,ref Key);


//tb.Buttons.Add(ref index,OWC10.OCCommandId.ocCommandCopy,OWC10.OCCommandId.ocCommandCopy,0,null);
} private void Form1_Load(object sender, System.EventArgs e)
{ } private void button2_Click(object sender, System.EventArgs e)
{
mscomctl.Toolbar tb = axPivotTable1.Toolbar;
mscomctl.ImageListClass il = (mscomctl.ImageListClass)tb.ImageList;
object index = il.ListImages.Count+1;
object Key = "imgRecalc";
object imageIndex=1;
mscomctl.ListImage ill = il.ListImages.get_Item(ref imageIndex);
mscomctl.ListImages lImages = il.ListImages;


//stdole.IPictureDisp imTemp;



System.Drawing.Icon im = new System.Drawing.Icon(@"C:\Chainet\My Documents\代码管理\其他项目\OWCsample\Recalc.ico");
//stdole.StdPictureClass imP = new stdole.StdPictureClass();
stdole.IPictureDisp imP = ill.Picture;


}