回 帖 发 新 帖 刷新版面

主题:无边框窗体怎样实现移动!(紧急需要)

无边框窗体怎样实现移动!(PictureBox或Pannel控件)

回复列表 (共7个回复)

沙发

VB中用到了API函数。。但是我也拷来试过。。上面有些方法不能够用。。我也不明白了。。

板凳

it's easy!
利用合用mousedown,mouseup,mousemove事件
---------------------------------------------------------------------------
    Public originalX, originalY As Integer
    Public startB As Boolean

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
        If startB = True Then
            Me.Top = Me.Top + (e.Y - originalY)
            Me.Left = Me.Left + (e.X - originalY)
        End If
    End Sub

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
        startB = True
        originalX = e.X
        originalY = e.Y
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        startB = False
    End Sub

    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
        startB = False
    End Sub
---------------------------------------------------------------------------

3 楼

it's easy!
利用合用mousedown,mouseup,mousemove事件
---------------------------------------------------------------------------
    Public originalX, originalY As Integer
    Public startB As Boolean

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
        If startB = True Then
            Me.Top = Me.Top + (e.Y - originalY)
            Me.Left = Me.Left + (e.X - originalY)
        End If
    End Sub

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
        startB = True
        originalX = e.X
        originalY = e.Y
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        startB = False
    End Sub

    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
        startB = False
    End Sub
---------------------------------------------------------------------------

4 楼

为什么不用消息呢?
SendMessage(me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
把上面这句加在窗体的MouseDown事件里

5 楼

SendMessage(me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
不是太明白啊,能不能说详细点,谢谢

6 楼

4楼那个是VC++里的应用...

7 楼

原本这个功能在vs6里面实现起来很复杂,需要调用winapi的消息传递
而在vs.net中,仅使用控件自己的封装方法就可以实现了

我来回复

您尚未登录,请登录后再回复。点此登录或注册