读书人

怎么让一个子窗口永远在最后面?请高手

发布时间: 2012-02-01 16:58:19 作者: rapoo

如何让一个子窗口永远在最后面?请高手帮忙!(在线等)
有一个子窗口A比较特别,要求当前另外一个子窗口B关闭后,如果还存在子窗口C的话,那么本来应该显示A的时候,不显示A,而去显示C,一句话,子窗口A永远显示在最后面!!
现在的想法就是在子窗口关闭的时候父窗口捕捉到这个事件,然后判断当前子窗口关闭后,下一个子窗口是不是A,如果是A的话,转移焦点。
问题就是父窗口好像没有捕捉子窗口关闭的事件,请高手帮帮忙!
还有如果有其他好的思路,请告诉我哦!
最好提供代码,VB.NET的。
在线等哦!!!

[解决办法]
Public Class Form1
'Inherits System.Windows.Forms.Form

' Constant value was found in the "windows.h " header file.
Private Const WM_ACTIVATEAPP As Integer = &H1C
Private appActive As Boolean = True

<STAThread()> _
Shared Sub Main()
Application.Run(New Form1())
End Sub 'Main

Public Sub New()
MyBase.New()

Me.Size = New System.Drawing.Size(300, 300)
Me.Text = "Form1 "
Me.Font = New System.Drawing.Font( "Microsoft Sans Serif ", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
InitializeComponent()
End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)


If (appActive) Then

Me.SendToBack()

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
End Class



[解决办法]
还没有解决?

我的代码是测试了的,应该可以,

更简单的办法是让formA加入下面代码:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)


Me.SendToBack()

End Sub

读书人网 >VB Dotnet

热点推荐