Private Const WM_ACTIVATEAPP As Integer = &H1C
Private appActive As Boolean = True
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
If (appActive) Then
e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, 20, 20, 260, 50)
e.Graphics.DrawString("程序获得焦点", Me.Font, SystemBrushes.ActiveCaptionText, 20, 20)
Else
e.Graphics.FillRectangle(SystemBrushes.InactiveCaption, 20, 20, 260, 50)
e.Graphics.DrawString("程序失去焦点", Me.Font, SystemBrushes.ActiveCaptionText, 20, 20)
End If
End Sub
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
Case WM_ACTIVATEAPP
appActive = (m.WParam.ToInt32() <> 0)
Me.Invalidate()
End Select
MyBase.WndProc(m)
End Sub