Help with forms class.

T

teejayem

I have a VB application with one main form. I also have a second form
that has the ShowInTaskbar property set to False.

If i click another application in the taskbar (for example:- Outlook)
then that application now has focus and covers up my application. If
I then click my application within the taskbar the main form is active
and is displayed above all other windows. The problem i have is that
the second form is still hidden behind all the other forms.

I thought that if i use the BringToFront() method within the
frmMain_GotFocus event it would also bring the second form to the
front but it doesn't. It seems that the GotFocus event is not fired
if i click my application within the taskbar.

Does anybody know what event I need?
 
A

Armin Zingler

I have a VB application with one main form. I also have a second
form that has the ShowInTaskbar property set to False.

If i click another application in the taskbar (for example:-
Outlook) then that application now has focus and covers up my
application. If I then click my application within the taskbar the
main form is active and is displayed above all other windows. The
problem i have is that the second form is still hidden behind all
the other forms.

I thought that if i use the BringToFront() method within the
frmMain_GotFocus event it would also bring the second form to the
front but it doesn't. It seems that the GotFocus event is not fired
if i click my application within the taskbar.

Does anybody know what event I need?


The Activated event. But, if you handle it in Form1 and call Form2's
Activate method, you will never be able to activate Form1: Each time you try
to activate it, Form2 is activated. Even if the application has not lost the
focus.

Therefore I would handle the case when the application is activated:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

Const WM_ACTIVATEAPP As Integer = &H1C

MyBase.WndProc(m)

If m.Msg = WM_ACTIVATEAPP AndAlso m.WParam <> IntPtr.Zero Then
Debug.WriteLine("application activated")
'--> insert code here <--
End If

End Sub

Though, what I don't understand: If you activate Form1 in the taskbar, why
do you want to activate Form2? You clicked on Form1. What you are trying is:
Always activate Form2 if the application gets the focus. If Form2 is that
important, why isn't it shown in the taskbar?

That's why I solely write MDI applications: All application windows in one
big frame. Don't know if it's possible with your application.


Armin
 
T

teejayem

The Activated event. But, if you handle it in Form1 and call Form2's
Activate method, you will never be able to activate Form1: Each time you try
to activate it, Form2 is activated. Even if the application has not lost the
focus.

Therefore I would handle the case when the application is activated:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

Const WM_ACTIVATEAPP As Integer = &H1C

MyBase.WndProc(m)

If m.Msg = WM_ACTIVATEAPP AndAlso m.WParam <> IntPtr.Zero Then
Debug.WriteLine("application activated")
'--> insert code here <--
End If

End Sub

Though, what I don't understand: If you activate Form1 in the taskbar, why
do you want to activate Form2? You clicked on Form1. What you are trying is:
Always activate Form2 if the application gets the focus. If Form2 is that
important, why isn't it shown in the taskbar?

That's why I solely write MDI applications: All application windows in one
big frame. Don't know if it's possible with your application.

Armin- Hide quoted text -

- Show quoted text -

Thanks mate.

I did try using the BringToFront() method within the frmMain_Activated
event procedure and I did come accross that problem!! how annoying!!

Thanks for the code mate, works brilliantly.
 
G

Guest

If I program an application with multiple forms and not within an MDI, I
always use a main form and other forms are shown as modal which should avoid
your problem.
 
A

Armin Zingler

Dennis said:
If I program an application with multiple forms and not within an
MDI, I always use a main form and other forms are shown as modal
which should avoid your problem.

It should avoid the problem but maybe he wants to show them modeless.

Another way is making Form1 the owner of Form2, but then Form2 is always in
front of Form1 - which might also be someting he does not want.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top