How to detect Help button press in Windows Forms MessageBox?

纵饮孤独 提交于 2019-12-01 17:59:07

问题


I have a message box with 3 buttons: Yes, No, Help:

var result = MessageBox.Show("text", "title",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning,
                MessageBoxDefaultButton.Button1,
                true);

I can detect if Yes/No buttons where clicked something like this:

if(result == DialogResult.Yes)
    // some actions

How I can detect that Help button was pressed and execute my own code?


回答1:


You want to handle the Form's HelpRequested event. See the example in the help topic.

public static DialogResult Show(
    string text,
    string caption,
    MessageBoxButtons buttons,
    MessageBoxIcon icon,
    MessageBoxDefaultButton defaultButton,
    MessageBoxOptions options,
    bool displayHelpButton
)


来源:https://stackoverflow.com/questions/2407880/how-to-detect-help-button-press-in-windows-forms-messagebox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!