0

Message I need to add a help button in my message box then find the answer here Clickable URL in a Winform Message Box? which is great! however, when I use this code inside a button then click the help button, it opens 2 tabs with the same link.

Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click

MessageBox.Show(
        "test message",
        "caption",
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Information,
        MessageBoxDefaultButton.Button1,
        0, '0 is default otherwise use MessageBoxOptions Enum
        "http://google.com",
        "keyword")

End Sub

-Update: I just tried it with the new project Winforms .NET 5.0 and it's working fine, but I need this on my current project.

  • Maybe your mouse is double clicking : ). Seriously, I copy pasted your code and it's only opening once for me. – crimson589 Jan 12 '22 at 03:06
  • Hi, Thank you for your response, I just tried with my laptop touchpad and asked my colleague to test the code and we got the same results. When I copy/paste it in the form onLoad, it only opens once, but with the event onClick of a button, it opens twice. – Vergel Mañalac Jan 12 '22 at 03:19
  • @VergelMañalac Is this a WinForms application or something else? Your code worked as expected for me on both .NET Framework and .NET 6.0. – 41686d6564 stands w. Palestine Jan 12 '22 at 03:25
  • @41686d6564 Yes, Winforms with .NET Framework 4.5 – Vergel Mañalac Jan 12 '22 at 03:27
  • @VergelMañalac No repro on .NET Framework 4.5. I suspect that something else is going on with your code and it's causing this side effect. Are you able to reproduce this in a brand new WinForms project using the _exact_ code that's currently in the post? – 41686d6564 stands w. Palestine Jan 12 '22 at 03:31
  • @41686d6564 - I just tried it with the new project Winforms .NET 5.0 and it's working fine, but I need this on my current project. – Vergel Mañalac Jan 12 '22 at 03:33
  • 1
    In that case, please try to create a [repro] so we can help you figure out the cause of the issue. As evidenced by both our tests, the code in question (on its own) does _not_ reproduce the issue. – 41686d6564 stands w. Palestine Jan 12 '22 at 03:34
  • @41686d6564 - You are correct, the problem is in my current project, I tried various projects and the code is perfectly working and but I don't know how to replicate this. – Vergel Mañalac Jan 12 '22 at 03:49
  • 1
    @41686d6564 - I saw this thread and I think we have the same issue but I don't really understand it. https://stackoverflow.com/questions/35458602/clicking-help-button-in-messagebox-loads-help-link-multiple-times – Vergel Mañalac Jan 12 '22 at 03:57
  • @VergelMañalac You're right; it _is_ the same issue. As per the answer to that question, you simply need to subscribe to the `HelpRequested` event of the form. You can either leave the event handler empty or (preferably) write `e.Handled = True`. I would also add a comment there explaining why the event handler is needed, for future reference. – 41686d6564 stands w. Palestine Jan 12 '22 at 04:13
  • @41686d6564 - It worked! Thank you very much! I really appreciate your help! – Vergel Mañalac Jan 12 '22 at 05:54
  • BTW, I have a method that I just need to call to execute this message box, if I subscribe to the `HelpRequested` event of the form, how can I apply this to all my forms? – Vergel Mañalac Jan 12 '22 at 06:42

0 Answers0