VB 如何用鼠标拖动Text控件,并固定到最后拖动的位置
VB如何用鼠标拖动Text控件,并固定到最后拖动的位置,也就是可以用鼠标改变Text的位置!...
VB 如何用鼠标拖动Text控件,并固定到最后拖动的位置,也就是可以用鼠标改变Text的位置!
展开
展开全部
更简单的代码如下:
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SYSTEXT = &H112
Private Const SC_MOVE = &HF010&
Private Const HTCAPTION = 2
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage Text1.hWnd, WM_SYSTEXT, SC_MOVE + HTCAPTION, 0
End If
End Sub
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SYSTEXT = &H112
Private Const SC_MOVE = &HF010&
Private Const HTCAPTION = 2
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage Text1.hWnd, WM_SYSTEXT, SC_MOVE + HTCAPTION, 0
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
简单模拟一下,你在一个窗体上画一个文本框,复制下面的代码,
运行后,拖动文本框,就可以看到效果了
Private Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
Text1.Left = X
Text1.Top = Y
End Sub
Private Sub Form_Load()
Text1.DragMode = 1
End Sub
运行后,拖动文本框,就可以看到效果了
Private Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
Text1.Left = X
Text1.Top = Y
End Sub
Private Sub Form_Load()
Text1.DragMode = 1
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Dim blnDragging As Boolean
Dim offsetX As Single, offsetY As Single
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDragging Then
Text1.Move X - offsetX, Y - offsetY
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnDragging = False
ReleaseCapture
End Sub
Private Sub text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
blnDragging = True
SetCapture Me.hwnd
offsetX = X
offsetY = Y
End If
End Sub
’新建一个textBox 把代码复制进去,试下。
Private Declare Function ReleaseCapture Lib "user32" () As Long
Dim blnDragging As Boolean
Dim offsetX As Single, offsetY As Single
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDragging Then
Text1.Move X - offsetX, Y - offsetY
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnDragging = False
ReleaseCapture
End Sub
Private Sub text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
blnDragging = True
SetCapture Me.hwnd
offsetX = X
offsetY = Y
End If
End Sub
’新建一个textBox 把代码复制进去,试下。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
就用鼠标拖动啊,想放拿就放哪,你不会是把Text属性设置为固定了吧?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询