#t#VB.NET经过长时间的发展,很多用户都很了解VB.NET窗体标题栏了,这里我发表一下个人理解,和大家讨论讨论。VB.NET做为VB6的升级版本,具备了许多新的功能,它可以简便快捷地创建 .NET 应用程序(包括 XML Web services 和 ASP.NET Web 应用程序),还是一个功能强大的面向对象的编程语言(如继承、接口和重载)。新的语言功能包括自由线程处理和结构化异常处理。VB.NET 还完全集成了.NET 框架和公共语言运行库,.NET 框架和公共语言运行库共同提供语言互操作性、垃圾回收、增强的安全性和改进的版本支持。可以说是一个划时代的产品!
无标题栏的窗体的拖动问题,在特殊窗体的应用中,我们有时需要把VB.NET窗体标题栏屏蔽掉,以窗体换上自己的外壳。是,当去掉了VB.NET窗体标题栏后,移动窗体就成了一个问题。我们还是来看一下在VB6中的实现,VB6中实现(借助API函数SendMessage)在设计时将窗体的BorderStyle属性设置为0-none
- PrivateDeclareFunction SendMessage Lib "User32" Alias "SendMessageA"
(ByVal hWnd AsLong, ByVal wMsg AsLong, ByVal wParam AsLong, ByVal lParam As Any) AsLong- PrivateDeclareSub ReleaseCapture Lib "User32" ()
- Const WM_NCLBUTTONDOWN = &HA1
- Const HTCAPTION = 2
- Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Dim lngReturnValue AsLong
- If Button = 1 Then
- 'Release capture
- Call ReleaseCapture()
- 'Send a 'left mouse button down on caption'-message to our form
- lngReturnValue = SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
- EndIf
- EndSub
- PrivateSub Form_Paint()
- Me.Print("Click on the form, hold the mouse button and drag it")
- EndSub
在VB.NET窗体标题栏中,这次需要借助API SendMessage了,在设计时将Form.FormBorderStyle 属性设置为None,然后添加以下代码:
- DeclareFunction SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd AsInteger, ByVal wMsg AsInteger, ByVal wParam AsInteger,
ByVal lParam AsInteger) AsInteger- PrivateDeclareSub ReleaseCapture Lib "User32" ()
- Const WM_NCLBUTTONDOWN = &HA1
- Const HTCAPTION = 2
- PrivateSub Form1_MouseDown(ByVal sender AsObject,
ByVal e As System.Windows.Forms.MouseEventArgs) HandlesMyBase.MouseDown- ReleaseCapture()
- SendMessage(Me.Handle.ToInt64, WM_NCLBUTTONDOWN, HTCAPTION, 0)
- EndSub