none
MessageBox with OK and Help button. Clicking on Help button is not showing the help RRS feed

  • Question

  • Microsoft,

    I have a requirement to show a MessageBox with OK and Help buttons in a Console Application. And on clicking of this Help button should show the context sensitive help.

    Code:  Below is the LOC iam using 

    MessageBox.Show("ABCD", "Caption is",
                      MessageBoxButtons.OK,
                      MessageBoxIcon.Information,
                      MessageBoxDefaultButton.Button2,
                      0, "abcHelp.chm",
                      HelpNavigator.TopicId, "123");

    Note that the same piece of code works fine in Winforms application. (Clicking help button help dialog displays).

    Can we do this in console application without showing the form?

    Thursday, November 8, 2018 5:05 AM

Answers

  • Dummy Form in the sense visually you cannot see the form as i made the size to 0,0 and FormBorderStyle  to None.

    Requirement is quiet simple. we want to display a MessageBox with OK and Help button and click on Help should display the help to the user. This should be done in a console application. Is this possible ?

    • Marked as answer by Anil Sanaka Monday, November 12, 2018 4:27 AM
    Friday, November 9, 2018 2:29 AM

All replies

  • Hi Anil,

    Of cause you can use the MessageBox.Show() method in the console application, only need to add "System.Windows.Forms" namespace.

    From the MSDN document about this method:

    When the user clicks the Help button, the Help file specified in the helpFilePath parameter is opened and the Help content identified by the navigator parameter is displayed. The form that owns the message box (or the active form) also receives the HelpRequested event.

    However, the console app does not contain an active form, I'm not sure if it is the real reason that you can not show the help message, maybe it is.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 8, 2018 5:46 AM
    Moderator
  • Yes you are right . In console application we wont be having an active form / a form .

    So until i create a dummyform (With no UI ) and call dummyform.show . This button click is not getting fired up. How can i overcome this ?

    Thursday, November 8, 2018 6:31 AM
  • Hi,

    What do you mean that create a dummyform without UI, how do you create it and how do you call it?

    Please provide more details.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 8, 2018 8:28 AM
    Moderator
  • public partial class DummyForm : Form
        {
            public DummyForm()
            {
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                this.ShowInTaskbar = false;
                this.Load += new EventHandler(DummyForm_Load);
            }

            void DummyForm_Load(object sender, EventArgs e)
            {
                this.Size = new Size(0, 0);
            }


        }
    }

    new DummyForm().Show();

           
    • Edited by Anil Sanaka Thursday, November 8, 2018 9:41 AM
    Thursday, November 8, 2018 9:25 AM
  • Hi,

    From the above code, I noticed you created a class inherited from Form, I think it has UI, the point I can not understand is what do you mean that create a dummyform without UI. And what is your real purpose?

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 9, 2018 1:50 AM
    Moderator
  • Dummy Form in the sense visually you cannot see the form as i made the size to 0,0 and FormBorderStyle  to None.

    Requirement is quiet simple. we want to display a MessageBox with OK and Help button and click on Help should display the help to the user. This should be done in a console application. Is this possible ?

    • Marked as answer by Anil Sanaka Monday, November 12, 2018 4:27 AM
    Friday, November 9, 2018 2:29 AM
  • Hi Anil,

    I'm afraid the short answer is no.

    As I said above, the "Help" button handle the HelpRequested event, and this event occurs when the user requests help for a control.

    In a Winform app, you can register the event like:

        this.HelpRequested += new System.Windows.Forms.HelpEventHandler (this.Form1_HelpRequested);

    But you can not do it in a Console app.

    For more details:

    http://msdn.microsoft.com/en-us/library/szwxe9we.aspx.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 12, 2018 3:32 AM
    Moderator
  • Thanks for the reply Stanly Fan.
    Monday, November 12, 2018 4:26 AM