Form on top

Adagio

Well-known member
Joined
Dec 12, 2005
Messages
162
Programming Experience
Beginner
How do you set a form to be on top of the other forms in the application (but not on top of other applications)

So far I have only found two ways to set the application on top:

Me.TopMost = True
and
frm.showDialog


But both sets the form to be on top of all windows, including windows of other applications
 
I think you're perhaps looking for the Owner or OwnedForms properties, this is commonly used for tool windows that stay in front of their owner, they also minimize/restore and close together with the owner.
 
But I get an error when I try to use owner: (and no, the form that calls this code is not frmEditQrapport)

frmEditQrapport = New frmEditQrapport(LoadMask.Qrapport)
frmEditQrapport.Owner = Me
frmEditQrapport.Show(Me)

"A circular control reference has been made. A control cannot be owned by or parented to itself"
 
It wouldn't matter if 'Me' was same type as frmEditQrapport because a new instance is created, so the objects are different (thus is not 'itself').

But what's that 'LoadMask.Qrapport'? Any chance for someone that knows nothing about what you are doing to replicate (and possibly solve) the problem?
 
LoadMask is just this:

VB.NET:
Public Enum LoadMask
 
Qrapport
AfslutQrapport
Skadescharteque
(etc)
 
End Enum

Nothing that should have anything to do with Owner as far as I can see

The new sub looks like this:

VB.NET:
Private loadMask As LoadMask
 
Public Sub New(ByVal wtl As LoadMask)
InitializeComponent()
 
loadMask = wtl
End Sub

And loadMask is not used before the user clicks on the button the form
 
Last edited by a moderator:
I see no problem with that, the code runs fine here.
 
The problem was with the line frmEditQrapport.Show(Me)... removing Me stopped the error

Everything seems to work now, thanks for the help :)
 
frm.Show(Me) wasn't a problem here.
You probably set TopMost=True somewhere in the process. (it is also a Designer property)
 
Yeah, I must have accidentally double-clicked in the topmost field in the properties box, it was set to true and I don't remember doing it

But I created a new test project where I used the same code, and there it worked with frm.show(me)
 
Back
Top