24

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)

Community
  • 1
  • 1
  • 6
    The linked question is tagged VB, not C#. The accepted answer does not show a hyperlink; it displays a Help button on the MessageBox that navigates to Google when clicked. You can achieve this by simply removing the asterisks. If you want an actual hyperlink, you have to create your own form. – JosephHirn Feb 11 '13 at 19:40
  • Thanks Ginosaji. This should be fine for me. –  Feb 11 '13 at 19:44

2 Answers2

43

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! :)

davmos
  • 9,324
  • 4
  • 40
  • 43
  • 1
    I had to adapt your code to work: `System.Windows.MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Do you like to go to google.com?", "My Window-Title", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Asterisk); if (messageBoxResult.ToString() == "Yes") { System.Diagnostics.Process.Start("http://www.google.com"); }` – else42.de Jun 12 '15 at 12:11
  • Note: On MessageBox result = yes this actually starts the OS default browser with the link. Rather than providing a clickable link within the MessageBox. – TazAstroSpacial Apr 26 '19 at 08:01
  • 1
    Question was to show a hyperlink in the message box. Link should open when clicked on Hyperlink. Instead this will open on button click after message box is closed. – The King Apr 05 '21 at 07:22
0

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

TaRDy
  • 999
  • 1
  • 8
  • 21