Results 1 to 15 of 15

Thread: MessageBox on TopMost Form.

  1. #1

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    MessageBox on TopMost Form.

    Hi! I have an application that, for some reason, has to be TopMost (over the other opened app'). But when MsgBox are called, the msg box appears behind the win form. Is there any way I can solve this... I checked in the help to see if there would not be any properties for the messagebox.show() function, but there's nothing about z-order (TopMost)... Anyone!?

    JCAvard
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: MessageBox on TopMost Form.

    Hmm how are you setting top most?? There's a topmost property for the form.. is this set to True or False?

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: MessageBox on TopMost Form.

    where is the messagebox being called from? I just tested and the messagebox appears above the topmost form

  4. #4

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    Re: MessageBox on TopMost Form.

    yes, topmost = true...

    VB Code:
    1. Private Sub mnuAlwaysOnTop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAlwaysOnTop.Click
    2.         If mnuAlwaysOnTop.Checked = True Then
    3.             mnuAlwaysOnTop.Checked = False
    4.             Me.TopMost = False
    5.             frmAbout.TopMost = False
    6.             frmFind.TopMost = False
    7.             frmOptions.TopMost = False
    8.             frmProperties.TopMost = False
    9.         Else
    10.             mnuAlwaysOnTop.Checked = True
    11.             Me.TopMost = True
    12.             frmAbout.TopMost = True
    13.             frmFind.TopMost = True
    14.             frmOptions.TopMost = True
    15.             frmProperties.TopMost = True
    16.         End If
    17.         Dim regKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\DSD International\\PlantClipArt")
    18.         regKey.SetValue("TopMost", mnuAlwaysOnTop.Checked)
    19.  
    20.     End Sub
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: MessageBox on TopMost Form.

    And where is the messagebox coming from...

    Also.. be sure the registry value is being read and changing the Topmost property correctly wherever that event is happening... The default of the form is TopMost = false (unless you change this in properties in designer)... when it loads, it will be set to false until you check the box, unless you are reading the registry value somewhere else and assigning the property on form load or something...
    Last edited by gigemboy; Sep 27th, 2005 at 03:44 PM.

  6. #6

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    Re: MessageBox on TopMost Form.

    yeah, I have a startup routine that checks all the regkey than set the properties according to the regkey value. and the messagebox come from error thrown and things like that. mainly from the frmMain form.
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  7. #7
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: MessageBox on TopMost Form.

    On the form that is supposedly set to topmost, try adding another messagebox after the error message of the supposed topmost form, that displays the current status of the topmost property (msgbox (me.topmost.tostring)..... my guess is that if you get to an errorbox that is not on the top of the topmost form, then that messagebox is either coming from a different form or the topmost property at that time isnt True, which would be shown in the messagebox after you click out the first error, displaying a "False" message.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MessageBox on TopMost Form.

    I would suggest not making all the other forms TopMost but making them owned forms instead. That way they will always be on top of your main window when they are visible, but they should not interfere with the MessageBox. To do this, the main form would set each child form's Owner property to Me.

    Also, you should definitely not be using the registry to store that TopMost value because TopMost is a dynamic property. All you have to do is go to the DynamicProperties for the form, in the Properties window, and check TopMost and it will be automatically saved to and retrieved from the app's config file.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: MessageBox on TopMost Form.

    Yes, but i think he is saving that because the user can decide whether the form is topmost or not..

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MessageBox on TopMost Form.

    Quote Originally Posted by gigemboy
    Yes, but i think he is saving that because the user can decide whether the form is topmost or not..
    I understand that, but dynamic properties do that automatically. If you check the TopMost property in the list of dynamic properties then its value will be loaded from the config file at startup and then it will be saved to the config file again at shutdown. This means that whatever you set it to in code will be automatically saved and used again next time the app runs. That's what dynamic properties and the config file are for. .NET apps are supposed to avoid the registry if at all possible.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: MessageBox on TopMost Form.

    Hmm.. Learn something new everyday... never used Dyanamic Properties before... now I understand

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MessageBox on TopMost Form.

    Quote Originally Posted by gigemboy
    never used Dyanamic Properties before
    I think most people haven't, nor even know they exist. I've read various mentions of the config file but I don't think I've ever read any post relating to dynamic properties. Only properties that are of a simple type, e.g. String, Integer, Double, etc. can be dynamic properties because they are the only types that can be saved as an XML attribute. Do a help search for "dynamic properties" and the first result describes how to create your own psuedo dynamic properties, which you can use for things like the Form.Location property, which is not a simple type so cannot be a true dynamic property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: MessageBox on TopMost Form.

    Thats where I went first, hence the "now I understand" comment

  14. #14

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    Re: MessageBox on TopMost Form.

    Thank you!

    I added
    VB Code:
    1. frmFind.owner = me
    2. frmFind.showDialog
    but it doesnt seem to do anything...
    As for the dynamic properties, if I set the form.topMost using a menu which the user can check or not. Will it work, because actually it doesnt seem to... Anyway, Ill work on that, thank you, that's appreciated!!
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MessageBox on TopMost Form.

    There's no point using an owned form that's displayed by calling ShowDialog. The idea of an owned form is that it does not block access to the caller but will always remain on top of the caller, just like the Find and Replace dialogue in Visual Studio. A modal dialogue will always be on top of the caller anyway. If you make your main form TopMost and the child forms owned then each of the children will always be on top of everything else.

    As for the dynamic property, have you checked the TopMost property in the list from the properties window? If so, you should find that it will automatically have the same value when the app starts as it had when it last closed. You shouldn't have to do anything more. Have you read the help topic I mentioned in post #12.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width