当前位置:编程学习 > C#/ASP.NET >>

怎么才能让在winform中用webbrowse打开的word自动显示工具栏(C#)

    我这自动弹出来“审计栏”,就是出不来工具栏,参考msdn上的代码,却发现我的 public void axWebBrowser1_NavigateComplete2 事件会执行2次,功能上倒是是打开doc文档和保存了


public partial class BobForm : Form
    {
        public BobForm()
        {
            InitializeComponent();
            this.wbDocView.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebBrowser1_NavigateComplete2);
            this.Load += new System.EventHandler(this.Form_Load);
            this.Closed += new System.EventHandler(this.Form_Closed);

        }

        private Object oDocument;

        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String strFileName;

            //Find the Office document.
            openFileDialog1.FileName = "";
            openFileDialog1.ShowDialog();
            strFileName = openFileDialog1.FileName;

            //If the user does not cancel, open the document.
            if (strFileName.Length != 0)
            {
                Object refmissing = System.Reflection.Missing.Value;
                oDocument = null;
                wbDocView.Navigate(strFileName, ref refmissing, ref refmissing, ref refmissing, ref refmissing);
               

            }

        }

        public void Form_Load(object sender, System.EventArgs e)
        {
            openFileDialog1.Filter = "Office Documents(*.doc)|*.doc";
            openFileDialog1.FilterIndex = 1;
        }

        public void Form_Closed(object sender, System.EventArgs e)
        {
            oDocument = null;
        }

        public void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
        {
            
            //Note: You can use the reference to the document object to 
            //      automate the document server.

            Object o = e.pDisp;

            oDocument = o.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, o, null);

            Object oApplication = o.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, oDocument, null);

            Object oName = o.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, oApplication, null);

            MessageBox.Show("File opened by: " + oName.ToString());
        }

        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            object missing = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Word.DocumentClass doc = oDocument as Microsoft.Office.Interop.Word.DocumentClass;
            doc.Save();
        }

        private void BobForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            wbDocView.Navigate("about:blank");
        }
    }
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,