office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

在Access中实现窗体内控件拖曳移动

2018-01-04 17:13:00
tmtony8
原创
5997

在Access窗体视图中,控件位置都是固定不变的。只有在布局视图或者在设计视图的时候才可以移动控件调整布局。

有的时候,程序操作可能被桌面的某个页面挡住了。我们是否可以稍微移动一下控件以致更好的实现操作呢?


下面示例实现在窗体视图中以拖曳的方式移动控件,只需要按住按钮“按着我拖曳移动”不放,拖动到需要的区域即可


详细源码:

Option Compare Database
'作者:在水一方
Private xx As Single
Private yy As Single
Private YD As Boolean

Private Sub Command0_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    xx = X
    yy = Y
    YD = True
End Sub

Private Sub Command0_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If YD = True Then
        a = Command0.Left + (X - xx)
        b = Command0.Top + (Y - yy)
        If a > 0 And a < 10000 And b < 10000 And b > 0 Then
            Command0.Move a, b
        End If
    End If
End Sub

    分享