如何移动VB中的无边框窗体
如何移动VB中的无边框窗体,borderstyle=0就是在窗口上按下鼠标可以拖动窗口请问如何实现...
如何移动VB中的无边框窗体,borderstyle=0
就是在窗口上按下鼠标 可以拖动窗口 请问如何实现 展开
就是在窗口上按下鼠标 可以拖动窗口 请问如何实现 展开
3个回答
展开全部
1、无边框窗体也就是无标题栏窗体,对于这样的窗体移动需要编程实现。
2、vb有两种办法实现,一直接编程实现,二调用windows API编程实现。
3、这里示例直接编程实现:
Option Explicit
Dim BolIsMove As Boolean, MousX As Long, MousY As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then BolIsMove = True
MousX = X
MousY = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim CurrX As Long, CurrY As Long
If BolIsMove Then
CurrX = Me.Left - MousX + X
CurrY = Me.Top - MousY + Y
Me.Move CurrX, CurrY
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
BolIsMove = False
End Sub
展开全部
在 BAS 文件中声明:
Declare Function ReleaseCapture Lib "user32" () As Long
Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Const HTCAPTION = 2
Public Const WM_NCLBUTTONDOWN = &HA1
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub
Declare Function ReleaseCapture Lib "user32" () As Long
Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Const HTCAPTION = 2
Public Const WM_NCLBUTTONDOWN = &HA1
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'以下是VB.NET鼠标移动无标题栏窗口 代码 , 加入到Class下,可实现窗口内任意位置移动无标题栏窗口
'==============================================================
Private IsFormBeingDragged As Boolean = False
Private MouseDownX As Integer '获取鼠标X
Private MouseDownY As Integer '获取鼠标Y
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = True
MouseDownX = e.X
MouseDownY = e.Y
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = False
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
If IsFormBeingDragged Then
Dim temp As Point = New Point()
temp.X = Me.Location.X + (e.X - MouseDownX)
temp.Y = Me.Location.Y + (e.Y - MouseDownY)
Me.Location = temp
temp = Nothing
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询