none
MessageBox.Show method with Help Button not opening help file from a VSTO Word Add-In

    Pregunta

  • The following works in a Winform application but not in my VSTO 2008 Word Add-In. You can use this MSDN Example for you testing. Also for your test, you can copy the mspaint.chm file from C:\WINDOWS\Help folder.

    MessageBox.Show("Test message", "Test title", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 0, "myHelpFile.chm", HelpNavigator.TopicId, "1001");

    When I click on the help button of the MessagBox in my Winform applicaion, the help file opens showing the correct topic but nothing happens when I click on the Help Button of the MessageBox in my Add-In. I have tried using the above code from the ThisAddIn.cs file and also in a WinForm included in my Add-In.

    I am using Office 2003 and the Add-In is application-level. I have copied the MyHelpFile.chm file in bin\Debug directory of both my application Winform and Add-In applications. I have tried it hard coding the full path of the file in the above code and also programmatically accessing the path of the file and storing it in a variable and replacing the “MyHelpFile.chm “with that variable.

    Please help. Thanks,

    Nam


    • Editado namwam lunes, 05 de marzo de 2012 3:41 Added an MSDN reference
    lunes, 05 de marzo de 2012 1:27

Respuestas

  • Hi namwam,

    I tried to reproduce your issue. I found it has limitation to show Help file via a MessageBox. The code alse doesn't work in a Form_Load method of a Windows Form application. If you use Help.ShowHelp you help file will show.

    using System;
    using System.Windows.Forms;
    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    using Excel = Microsoft.Office.Interop.Excel;
    using Office = Microsoft.Office.Core;
    
    namespace ExcelAddIn1
    {
        public partial class ThisAddIn
        {
            private Office.CommandBar nb = null;
            private Office.CommandBarControl bt = null;
            private Office.CommandBarButton btn = null;
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                #region VSTO generated code
    
                this.Application = (Excel.Application)Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Wrap(typeof(Excel.Application), this.Application);
    
                #endregion
                Excel.Application xlApp = Application;
                nb = xlApp.CommandBars["Worksheet Menu Bar"];
                bt = nb.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true);
                bt.Caption = "test";
                btn = (Office.CommandBarButton)((Office.CommandBarPopup)bt).Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, true);
                btn.Caption = "Alert";
                btn.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btn_Click);
            }
    
            void btn_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
            {
                //The commented code will not work!
                //MessageBox.Show(Environment.CurrentDirectory, "Test", MessageBoxButtons.OK, MessageBoxIcon.Question,
                //    MessageBoxDefaultButton.Button1, 0, "test.chm", HelpNavigator.TopicId, "1001");
                Form1 frm = new Form1();
                frm.Show();
                Help.ShowHelp(null, "test.chm",HelpNavigator.TopicId, "1001");
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
            
            #endregion
        }
    }


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace ExcelAddIn1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show(Environment.CurrentDirectory, "Test", MessageBoxButtons.OK, MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button1, 0, "test.chm", HelpNavigator.TopicId, "1001");
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    			//The commented code will not work
                //MessageBox.Show(Environment.CurrentDirectory, "Test", MessageBoxButtons.OK, MessageBoxIcon.Question,
                //    MessageBoxDefaultButton.Button1, 0, "test.chm", HelpNavigator.TopicId, "1001");
            }
        }
    }

    And the correct path of the Help file is MyDocuments folder.

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marcado como respuesta Bruce Song miércoles, 04 de abril de 2012 3:10
    martes, 06 de marzo de 2012 10:39

Todas las respuestas

  • Hi namwam,

    Thanks for posting in the MSDN Forum.

    I'm preparing the environment to reproduce your issue now. There might be some time delay. I will come back as fast as I can, appreciate for your patience.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    martes, 06 de marzo de 2012 7:54
  • Hi namwam,

    I tried to reproduce your issue. I found it has limitation to show Help file via a MessageBox. The code alse doesn't work in a Form_Load method of a Windows Form application. If you use Help.ShowHelp you help file will show.

    using System;
    using System.Windows.Forms;
    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    using Excel = Microsoft.Office.Interop.Excel;
    using Office = Microsoft.Office.Core;
    
    namespace ExcelAddIn1
    {
        public partial class ThisAddIn
        {
            private Office.CommandBar nb = null;
            private Office.CommandBarControl bt = null;
            private Office.CommandBarButton btn = null;
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                #region VSTO generated code
    
                this.Application = (Excel.Application)Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Wrap(typeof(Excel.Application), this.Application);
    
                #endregion
                Excel.Application xlApp = Application;
                nb = xlApp.CommandBars["Worksheet Menu Bar"];
                bt = nb.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true);
                bt.Caption = "test";
                btn = (Office.CommandBarButton)((Office.CommandBarPopup)bt).Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, true);
                btn.Caption = "Alert";
                btn.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btn_Click);
            }
    
            void btn_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
            {
                //The commented code will not work!
                //MessageBox.Show(Environment.CurrentDirectory, "Test", MessageBoxButtons.OK, MessageBoxIcon.Question,
                //    MessageBoxDefaultButton.Button1, 0, "test.chm", HelpNavigator.TopicId, "1001");
                Form1 frm = new Form1();
                frm.Show();
                Help.ShowHelp(null, "test.chm",HelpNavigator.TopicId, "1001");
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
            
            #endregion
        }
    }


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace ExcelAddIn1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show(Environment.CurrentDirectory, "Test", MessageBoxButtons.OK, MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button1, 0, "test.chm", HelpNavigator.TopicId, "1001");
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    			//The commented code will not work
                //MessageBox.Show(Environment.CurrentDirectory, "Test", MessageBoxButtons.OK, MessageBoxIcon.Question,
                //    MessageBoxDefaultButton.Button1, 0, "test.chm", HelpNavigator.TopicId, "1001");
            }
        }
    }

    And the correct path of the Help file is MyDocuments folder.

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marcado como respuesta Bruce Song miércoles, 04 de abril de 2012 3:10
    martes, 06 de marzo de 2012 10:39