软件介绍:如果鼠标拖动时控件尺寸变化太灵敏,您可以通过限制调整大小的范围或者设置一个阈值来解决这个问题。以下是一种可行的方法:1. 在 `General` 声明区域添加以...
如果鼠标拖动时控件尺寸变化太灵敏,您可以通过限制调整大小的范围或者设置一个阈值来解决这个问题。以下是一种可行的方法:
1. 在 `General` 声明区域添加以下变量:
Dim dragging As Boolean Dim startX As Single Dim startY As Single
2. 将以下代码放置在 `Picture1` 控件的 `MouseDown` 事件处理程序中:
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then dragging = True startX = X startY = Y End If End Sub
3. 将以下代码放置在 `Picture1` 控件的 `MouseMove` 事件处理程序中:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If dragging Then Dim deltaX As Single Dim deltaY As Single deltaX = X - startX deltaY = Y - startY ' 设置移动阈值(例如,限制每次拖动至少移动10个像素) Const threshold As Integer = 10 If Abs(deltaX) >= threshold Or Abs(deltaY) >= threshold Then Picture1.Width = Picture1.Width + deltaX Picture1.Height = Picture1.Height + deltaY startX = X startY = Y End If End If End Sub
4. 最后,在 `Picture1` 控件的 `MouseUp` 事件处理程序中重置 `dragging` 标志:
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then dragging = False End If End Sub
控件只会在达到指定的阈值(例如10个像素)后才会随鼠标拖动而调整大小。您可以根据需要调整阈值大小以满足您的要求。这样,稍微一拖动就不会导致全屏效果。