<te******@gmail.comschrieb
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