vb运行时为什么拖动控件一直在抖动
展开全部
二楼说的对。一楼别吵。
二楼也不全对,Windows 的重新绘制很快,除非是复杂的图像。举例:虽然每动一个像素都会重绘,但是拖动窗口时一般并没有使人发狂。
我一开始想要做一个自定义标题栏的程序时就用了 Label 来拖动,结果出现了如题的问题。
如果你想要移动窗体(鼠标拖动移动,不按标题栏),可以参考这段代码。绝对可行,而且有效避免了拼命刷屏的错误。
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim Pt As POINTAPI
Dim lastX As Long, lastY As Long, bMoving As Boolean
Private Sub Form_DblClick()
End
End Sub
Private Sub Form_Load()
'redirect all mouse input to this form
'SetCapture Me.hwnd
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
GetCursorPos Pt
lastX = Pt.X
lastY = Pt.Y
ReleaseCapture
SetCapture Me.hwnd
bMoving = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Get the current cursor position
If bMoving Then
GetCursorPos Pt
Me.Move Me.Left + (Pt.X - lastX) * Screen.TwipsPerPixelX, Me.Top + (Pt.Y - lastY) * Screen.TwipsPerPixelY
lastX = Pt.X
lastY = Pt.Y
'SetCapture Me.hwnd
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
bMoving = False
'SetCapture Me.hwnd
End Sub
二楼也不全对,Windows 的重新绘制很快,除非是复杂的图像。举例:虽然每动一个像素都会重绘,但是拖动窗口时一般并没有使人发狂。
我一开始想要做一个自定义标题栏的程序时就用了 Label 来拖动,结果出现了如题的问题。
如果你想要移动窗体(鼠标拖动移动,不按标题栏),可以参考这段代码。绝对可行,而且有效避免了拼命刷屏的错误。
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim Pt As POINTAPI
Dim lastX As Long, lastY As Long, bMoving As Boolean
Private Sub Form_DblClick()
End
End Sub
Private Sub Form_Load()
'redirect all mouse input to this form
'SetCapture Me.hwnd
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
GetCursorPos Pt
lastX = Pt.X
lastY = Pt.Y
ReleaseCapture
SetCapture Me.hwnd
bMoving = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Get the current cursor position
If bMoving Then
GetCursorPos Pt
Me.Move Me.Left + (Pt.X - lastX) * Screen.TwipsPerPixelX, Me.Top + (Pt.Y - lastY) * Screen.TwipsPerPixelY
lastX = Pt.X
lastY = Pt.Y
'SetCapture Me.hwnd
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
bMoving = False
'SetCapture Me.hwnd
End Sub
展开全部
在Windows操作系统中,任何可见的东西都是靠代码绘制或者从硬盘读出的图片绘制在屏幕上。
VB中的控件也是这样。绘制一个控件的过程相当繁琐复杂,而拖动是一个持续性的操作,每拖动一个像素控件都要被重新绘制,所以会闪烁。
VB中的控件也是这样。绘制一个控件的过程相当繁琐复杂,而拖动是一个持续性的操作,每拖动一个像素控件都要被重新绘制,所以会闪烁。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你手在抖吧?o(∩_∩)o 哈哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询