Bringing second form to front when first gets focus (keeping both windows on top)

  • Thread starter Thread starter papalarge
  • Start date Start date
P

papalarge

I have a VB.NET application that consists of a toolbar and a subwindow
that I want to function together and not independently. So when I
give focus to one, I want to make sure that the other is visible on
the screen (brought to front, right behind the one in focus).

I've played with the activated event of each form, but everything I've
tried so far fails, as it's a pretty cyclical process that gets
initiated. I'd love any help... here's what I have so far that
doesn't work... heh.

-----------------------
'PUBLIC
Dim bIgnoreActivation as Boolean = False
-----------------------
'SUB-WINDOW

Private Sub frmSubWindow_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated

'IF THIS WAS THE ORIGINAL WINDOW GIVEN FOCUS
If Not bIgnoreActivation Then
'SET OUR IGNORE FLAG SO THE OTHER WINDOW
'KNOWS IT WASN'T ORIGINALLY CALLED
bIgnoreActivation = True
frmToolbar.BringToFront()
End If

Me.BringToFront()

'SET THE FLAG BACK
bIgnoreActivation = False

End Sub

------------------------
'TOOLBAR

Private Sub frmToolbar_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated

'IF THIS WAS THE ORIGINAL WINDOW GIVEN FOCUS
If Not bIgnoreActivation Then
'SET OUR IGNORE FLAG SO THE OTHER WINDOW
'KNOWS IT WASN'T ORIGINALLY CALLED
bIgnoreActivation = True
frmSubWindow.BringToFront()
End If

Me.BringToFront()

'SET THE FLAG BACK
bIgnoreActivation = False
End Sub
 
papalarge said:
I have a VB.NET application that consists of a toolbar and a
subwindow

I guess this means a toolbar /window/ and a sub window. Otherwise it sounds
like a free floating toolbar and a sub window of that toolbar.

Have you tried passing the toolbar window as the owner of the sub window?
In toolbar window:
dim t as new subwindow
t.show(me)

It does have influence on the focus, like the sub window automatically being
minimized whenever you minimize the toolbar window (IIRC), but I don't know
if it also has the effect you're looking for.


Armin
 
Yeah, toolbar + subwindow is right...

What's the inherited baseclass of subwindow? Can't find that in
VB.NET....
 
Didn't understand you at first, but just got it working a second ago.
On form load, set the subwindows owner to the toolbar, which allowed
them coincide when they receive focus.

Thanks Armin!
 
Back
Top