|
-
Sep 27th, 2005, 03:21 PM
#1
Thread Starter
Fanatic Member
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
-
Sep 27th, 2005, 03:29 PM
#2
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?
-
Sep 27th, 2005, 03:33 PM
#3
Re: MessageBox on TopMost Form.
where is the messagebox being called from? I just tested and the messagebox appears above the topmost form
-
Sep 27th, 2005, 03:34 PM
#4
Thread Starter
Fanatic Member
Re: MessageBox on TopMost Form.
yes, topmost = true...
VB Code:
Private Sub mnuAlwaysOnTop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAlwaysOnTop.Click
If mnuAlwaysOnTop.Checked = True Then
mnuAlwaysOnTop.Checked = False
Me.TopMost = False
frmAbout.TopMost = False
frmFind.TopMost = False
frmOptions.TopMost = False
frmProperties.TopMost = False
Else
mnuAlwaysOnTop.Checked = True
Me.TopMost = True
frmAbout.TopMost = True
frmFind.TopMost = True
frmOptions.TopMost = True
frmProperties.TopMost = True
End If
Dim regKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\DSD International\\PlantClipArt")
regKey.SetValue("TopMost", mnuAlwaysOnTop.Checked)
End Sub
-
Sep 27th, 2005, 03:37 PM
#5
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.
-
Sep 27th, 2005, 03:45 PM
#6
Thread Starter
Fanatic Member
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.
-
Sep 27th, 2005, 04:06 PM
#7
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.
-
Sep 27th, 2005, 06:47 PM
#8
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.
-
Sep 27th, 2005, 07:36 PM
#9
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..
-
Sep 27th, 2005, 07:43 PM
#10
Re: MessageBox on TopMost Form.
 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.
-
Sep 28th, 2005, 12:35 AM
#11
Re: MessageBox on TopMost Form.
Hmm.. Learn something new everyday... never used Dyanamic Properties before... now I understand
-
Sep 28th, 2005, 12:51 AM
#12
Re: MessageBox on TopMost Form.
 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.
-
Sep 28th, 2005, 01:22 AM
#13
Re: MessageBox on TopMost Form.
Thats where I went first, hence the "now I understand" comment
-
Sep 28th, 2005, 07:44 AM
#14
Thread Starter
Fanatic Member
Re: MessageBox on TopMost Form.
Thank you!
I added
VB Code:
frmFind.owner = me
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!!
-
Sep 28th, 2005, 09:01 AM
#15
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|