Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MessageBox Appearing Behind Window

MessageBox Appearing Behind Window

Scheduled Pinned Locked Moved C#
helpquestion
8 Posts 5 Posters 17 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Richard Andrew x64R Offline
    Richard Andrew x64R Offline
    Richard Andrew x64
    wrote on last edited by
    #1

    I'm having a problem with a MessageBox.Show() call. It's being called from a window that was shown with Form.ShowDialog(). The problem is that the message box sometimes appears behind the dialog box, and makes the dialog box unresponsive until the message box window is found and OK is clicked on it. This would be terribly confusing for users. Is there any way to guarantee that a message box is displayed above the form that is calling it?

    The difficult we do right away... ...the impossible takes slightly longer.

    OriginalGriffO L realJSOPR M 4 Replies Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      I'm having a problem with a MessageBox.Show() call. It's being called from a window that was shown with Form.ShowDialog(). The problem is that the message box sometimes appears behind the dialog box, and makes the dialog box unresponsive until the message box window is found and OK is clicked on it. This would be terribly confusing for users. Is there any way to guarantee that a message box is displayed above the form that is calling it?

      The difficult we do right away... ...the impossible takes slightly longer.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      The problem is that ShowDialog is a blocking call: it doesn't return control to the UI thread until the dialog has been dismissed. And MessageBox.Show is also a blocking call: it's the equivelant of calling ShowDialog on a "normal" form. You don't really have many options here other than to create your own message box and call Show on that if you must be able to continue working with it visible.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        I'm having a problem with a MessageBox.Show() call. It's being called from a window that was shown with Form.ShowDialog(). The problem is that the message box sometimes appears behind the dialog box, and makes the dialog box unresponsive until the message box window is found and OK is clicked on it. This would be terribly confusing for users. Is there any way to guarantee that a message box is displayed above the form that is calling it?

        The difficult we do right away... ...the impossible takes slightly longer.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You need a different "pattern". If the "error" is critical, exit the dialog, then give the message; then "retry" based on ok / cancel. Or the "dialog" might function better as a "wizard" (next; back; cancel).

        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

        Richard Andrew x64R 1 Reply Last reply
        0
        • L Lost User

          You need a different "pattern". If the "error" is critical, exit the dialog, then give the message; then "retry" based on ok / cancel. Or the "dialog" might function better as a "wizard" (next; back; cancel).

          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          These are great ideas, thanks!

          The difficult we do right away... ...the impossible takes slightly longer.

          L 1 Reply Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            These are great ideas, thanks!

            The difficult we do right away... ...the impossible takes slightly longer.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            You're welcome!

            "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

            1 Reply Last reply
            0
            • Richard Andrew x64R Richard Andrew x64

              I'm having a problem with a MessageBox.Show() call. It's being called from a window that was shown with Form.ShowDialog(). The problem is that the message box sometimes appears behind the dialog box, and makes the dialog box unresponsive until the message box window is found and OK is clicked on it. This would be terribly confusing for users. Is there any way to guarantee that a message box is displayed above the form that is calling it?

              The difficult we do right away... ...the impossible takes slightly longer.

              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #6

              Assuming you're using WPF... You could try my Customizable WPF MessageBox[^].

              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
              -----
              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
              -----
              When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

              1 Reply Last reply
              0
              • Richard Andrew x64R Richard Andrew x64

                I'm having a problem with a MessageBox.Show() call. It's being called from a window that was shown with Form.ShowDialog(). The problem is that the message box sometimes appears behind the dialog box, and makes the dialog box unresponsive until the message box window is found and OK is clicked on it. This would be terribly confusing for users. Is there any way to guarantee that a message box is displayed above the form that is calling it?

                The difficult we do right away... ...the impossible takes slightly longer.

                M Offline
                M Offline
                M Imran Ansari
                wrote on last edited by
                #7

                When you call MessageBox.Show(), you can pass the owner form as a parameter. This ensures that the message box will always be displayed above the owner form.

                Richard Andrew x64R 1 Reply Last reply
                0
                • M M Imran Ansari

                  When you call MessageBox.Show(), you can pass the owner form as a parameter. This ensures that the message box will always be displayed above the owner form.

                  Richard Andrew x64R Offline
                  Richard Andrew x64R Offline
                  Richard Andrew x64
                  wrote on last edited by
                  #8

                  Thanks! I'll try this.

                  The difficult we do right away... ...the impossible takes slightly longer.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups