各位大侠,请问如何让我的窗体的TOP与Left值等于Mouse的移动时的坐标值,使窗体随着Mouse走??

HowardOK 2002-01-10 11:50:09
...全文
99 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fuxc 2002-01-11
  • 打赏
  • 举报
回复
Dim fX, fY As Single

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
fX = X
fY = Y
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button > 0 Then Me.Move Me.Left - fX + X, Me.Top - fY + Y
End Sub
ndlxn 2002-01-11
  • 打赏
  • 举报
回复
看来还要加个timer,在里面随时GetCursorPos()
Iamfish 2002-01-11
  • 打赏
  • 举报
回复

先用getcursor() [api]取得当前的鼠标位置,再把me.top=mouse.y:me.left=mouse.x
注意,getcursor() 返回的是像素值!
HowardOK 2002-01-11
  • 打赏
  • 举报
回复
我并不是想这样,我是想我的鼠标在屏幕任何地方点击一下,我的窗体就在那个地方出现!!
ljren_t 2002-01-11
  • 打赏
  • 举报
回复
忘了写说明,在窗体任意位置上按下鼠标就可以拖动它.
ljren_t 2002-01-11
  • 打赏
  • 举报
回复
Option Explicit

Private Const HIT_CAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1

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)

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HIT_CAPTION, 0
End Sub
HowardOK 2002-01-11
  • 打赏
  • 举报
回复
就是无了回答我!!!
HowardOK 2002-01-11
  • 打赏
  • 举报
回复
怎么无人回答我呢!!!!!
HowardOK 2002-01-11
  • 打赏
  • 举报
回复
怎么无人回答我呢!!!!!
ljren_t 2002-01-11
  • 打赏
  • 举报
回复
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 GetCapture Lib "user32" () As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private blnIsDown As Boolean
Private blnIsCtrlDown As Boolean


Private xpoint As POINTAPI



Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 17 Then
blnIsCtrlDown = True
End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 17 Then
blnIsCtrlDown = False
End If
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
MouseManange x, y
blnIsDown = True

End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
MouseManange x, y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
MouseManange x, y
If blnIsCtrlDown Then
If blnIsDown Then
GetCursorPos xpoint
Me.Top = xpoint.y * 15
Me.Left = xpoint.x * 15
blnIsDown = False
End If
End If
End Sub
Private Sub MouseManange(x As Single, y As Single)
If blnIsCtrlDown Then
If GetCapture() <> Me.hWnd Then SetCapture Me.hWnd
ElseIf ((x < 0) Or (y < 0) Or (x > Me.Width) Or (y > Me.Height)) Then
ReleaseCapture
End If
End Sub

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧