悬赏园豆:50
[已关闭问题]
关闭于 2008-06-02 18:34
<P>代码如下:</P>
<P>我在EXCEL中添加了一个菜单按纽,但动作有时失效,经常性不能弹出我想要的窗口.</P>
<P>请高手帮忙看下,在此谢过!!! </P>
<P>public Form1()<BR> {<BR> InitializeComponent();<BR> }</P>
<P> private void button1_Click(object sender, EventArgs e)<BR> {<BR> Excel.Application app = new Excel.Application();<BR> app.Visible = true;<BR> app.UserControl = true;<BR> //<BR> Excel.Workbook wookBook = app.Workbooks.Add(Type.Missing);<BR> Office.CommandBar cmd = app.CommandBars.ActiveMenuBar;</P>
<P> Office.CommandBarControl ctrl = cmd.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true);<BR> ctrl.Caption = "测试菜单";</P>
<P> Office.CommandBarButton ctrl1 = ((Office.CommandBarPopup)ctrl).Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, true) as Office.CommandBarButton;<BR> ctrl1.Caption = "测试菜单11";</P>
<P> ctrl1.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(ctrl1_Click);</P>
<P> }</P>
<P> private void ctrl1_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)<BR> {<BR> Form2 f = new Form2();<BR> f.ShowDialog();<BR> //MessageBox.Show(CancelDefault.ToString());<BR> }</P>
问题补充:
1,通过一个Windowapplication打开一个EXCEL
2,如果弹出的EXCEL在windowapplication的上层,(当前活动的窗体为EXCEL),则EXCEL的自定义菜单弹出窗体没有问题 ,
3,如果相反 弹出的EXCEL在windowapplication的下层,(当前活动的窗体为windowapplication),点击EXCEL,切换当前活动窗体为EXCEL。此时EXCEL的自定义菜单弹出窗体失效。
jizh
|
初学一级
|
园豆:
104
提问于:2008-05-23 21:12