dcsimg
Results 1 to 6 of 6

Thread: [RESOLVED] MsgBox appears at behind everything

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    110

    Resolved [RESOLVED] MsgBox appears at behind everything

    I have a program that, before the main form shows up, asks for a save file and, if that file already exists, asks if the person wants to load from it first. (Yes, not elegant or pretty, but it's only for personal use anyway.) The problem is that right after selecting a file that already exists (and selecting 'yes' to the overwrite, as is part of the normal dialogue box), the MsgBox prompt asking if the load is wanted appears behind everything, even Visual Studio. The only way to get to it is to click its icon in the task bar.
    Is there an easy way to bring this to the front so it can be answered?

    EDIT: As pointed out later, forgot to add the code (because I thought it was too simple, my bad).

    Code:
        Dim theFile as String
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If sfdSave.ShowDialog = DialogResult.OK Then
                theFile = sfdSave.FileName
                If IO.File.Exists(theFile) Then
                    If MsgBox("Load First?", vbYesNo) = MsgBoxResult.Yes Then
                        'stuff
                    End If
                End If
            End If
        End Sub
    Last edited by OddGamer; Jun 20th, 2019 at 11:17 AM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,478

    Re: MsgBox appears at behind everything

    This isn't something that we should ever have to say: show us the code. If you want help to fix code that doesn't work, keeping that code a secret is about the worst thing you can do.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    110

    Re: MsgBox appears at behind everything

    Sorry about that. I didn't think it was too complicated a set-up. My bad.

    Code:
        Dim theFile as String
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If sfdSave.ShowDialog = DialogResult.OK Then
                theFile = sfdSave.FileName
                If IO.File.Exists(theFile) Then
                    If MsgBox("Load First?", vbYesNo) = MsgBoxResult.Yes Then
                        'stuff
                    End If
                End If
            End If
        End Sub
    Add a SaveFileDialogue on the main form called sfdSave and you're good to go.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,320

    Re: MsgBox appears at behind everything

    Nothing really jumps out at me from that code. I don't know if the legacy MsgBox behaves any differently from the .NET MessageBox.Show. This seems like an excellent opportunity to find out. It would be pretty interesting if MessageBox.Show solved the problem...especially since it shouldn't.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    110

    Re: MsgBox appears at behind everything

    Quote Originally Posted by Shaggy Hiker View Post
    I don't know if the legacy MsgBox behaves any differently from the .NET MessageBox.Show. This seems like an excellent opportunity to find out. It would be pretty interesting if MessageBox.Show solved the problem...especially since it shouldn't.
    Tried it. It doesn't. Same problem. Right after loading the file, the message box appears in the background.

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,082

    Re: MsgBox appears at behind everything

    It's because you are triggering the message box from the form's Load event. The form isn't shown yet, but MsgBox doesn't care. Instead use the Shown event handler.
    BB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width