How to create Hyperlink in MessageBox.show? [dupli

2019-04-18 17:47发布

问题:

This question already has an answer here:

  • Clickable URL in a Winform Message Box? 5 answers

I have tried creating a hyperlink in MessageBox in this way:

MessageBox.Show(
    "test message",
    "caption",
    MessageBoxButtons.YesNo,
    MessageBoxIcon.Information,
    MessageBoxDefaultButton.Button1,
    0,
    **"http://google.com"**,
    "Keyword"
);

Note: The Above code was actually "chosen as a answer" in an another question https://stackoverflow.com/a/1833877/2046417 ,but I don't know why its not working for me. I am getting error at keyword (Error 3 The * or -> operator must be applied to a pointer C:\Users\kiriti\Documents\Visual Studio 2010\Projects\TailorApplication_3\TailorApplication_3\Form1.cs 359 140 TailorApplication_3)

回答1:

I tried playing around with the code and found a solution to my own question.

if (MessageBox.Show(
        "test", "Visit", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk
    ) == DialogResult.Yes)
{
    System.Diagnostics.Process.Start("http://www.google.com");
}

Works great! :)



回答2:

The example given is for VB, if you remove the ** from the URL it will show the message box and take you to that URL when the help button is clicked.

For more information on the parameters of this call, see:

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