打印本文 打印本文 关闭窗口 关闭窗口
从VB 6到VB.NET——窗体特殊应用
作者:武汉SEO闵涛  文章来源:敏韬网  点击数4529  更新时间:2009/4/23 19:01:50  文章录入:mintao  责任编辑:mintao
;  Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long

    Private Declare Sub 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 As Long

        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&)

        End If

    End Sub

    Private Sub Form_Paint()

        Me.Print("Click on the form, hold the mouse button and drag it")

    End Sub

 

 

在VB.NET中,这次需要借助API SendMessage 了

在设计时将Form.FormBorderStyle 属性设置为None,然后添加以下代码:

    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

 

    Private Declare Sub ReleaseCapture Lib "User32" ()

    Const WM_NCLBUTTONDOWN = &HA1

    Const HTCAPTION = 2

 

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

        ReleaseCapture()

        SendMessage(Me.Handle.ToInt64, WM_NCLBUTTONDOWN, HTCAPTION, 0)

End Sub

 

三、结束语

以上实例在Windows 2000,VB6,VS.NET环境下运行通过。从以上实例,我们可以看到,以前VB6没有的好多属性和方法,在VB.NET中已经提供了出来,而且.NET提供了许多类库,可以完成在VB6中需要借助大量的API才能实现的操作。比如说构建一个多线程应用程序,用VB.NET就很容易了!更值得一提的就是,VB.NET是完全的面向对象,更加容易封装我们的业务逻辑,构建N层应用程序等企业级应用。我爱VB6,更爱.NET!

 

上一页  [1] [2] [3] [4] [5] 

打印本文 打印本文 关闭窗口 关闭窗口