0

I want to add a link, when the message appears, there is an ok button, when they click it will lead to the target URL link, how do I do it, can you help me

Public Shared Sub NewsInfo()
    MessageBox.Show("this message will appear")
End Sub

I have tried but error

If MessageBox.Show(Program."Demo version", MessageBoxButtons.YesNo) = DialogResult.Yes Then
    New Process() With { .StartInfo = { .FileName = "http://www.google.com" } }.Start()             
End If
5
  • 2
    You don't. The MessageBox class just displays a message. If you want more than that, you need to create your own form and display that. Internally, MessageBox.Show just creates a form with the appropriate controls, calls ShowDialog on it and then returns the appropriate DialogResult. You can do the same with your own form. Commented Nov 30, 2023 at 4:06
  • can you give an example of how to do it ?? I have tried but error If MessageBox.Show(Program."Demo version", MessageBoxButtons.YesNo) = DialogResult.Yes Then New Process() With { .StartInfo = { .FileName = "http://www.google.com" } }.Start() End If Commented Nov 30, 2023 at 4:12
  • 2
    I think I misunderstood you. I thought you were saying that you wanted to actually display a hyperlink that the user could click. If you're just saying that you want to open a URL then just open a URL. That's not a "link". Commented Nov 30, 2023 at 7:29
  • 1
    As for the issue, you say that you get an error but you don't tell us what the error message is or exactly where it occurs. That is never acceptable. That's always relevant information. That said, this part looks nonsensical: Program."Demo version". What exactly are you trying to achieve there? What is Program and what do you think ."Demo version" should do there? Commented Nov 30, 2023 at 7:32
  • 1
    If you want to open a URL in the default browser, just call Process.Start(url). Anything else is complicating things unnecessarily. I doubt that has anything to do with your issue though, as indicated above. Commented Nov 30, 2023 at 7:33

1 Answer 1

0

thanks for the help

if (MessageBox.Show(
        "test", "Visit", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk
    ) == DialogResult.Yes)
{
    System.Diagnostics.Process.Start("http://www.google.com");
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.