| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 971 人关注过本帖
标题:[求助]怎样让一个Image控件跟随鼠标指针
只看楼主 加入收藏
找不到服务器
Rank: 4
等 级:贵宾
威 望:12
帖 子:2937
专家分:1
注 册:2006-8-29
结帖率:33.33%
收藏
 问题点数:0 回复次数:2 
[求助]怎样让一个Image控件跟随鼠标指针

怎样让一个Image控件或Picture控件跟随鼠标指针
这个和拖动无标题窗口差不多

拖动无标题窗口
通常我们是拖动标题栏来移动窗口,当没有标题栏时,该如何来拖动窗口呢?方法是 当我们在窗口区按下鼠标左键时,调用ReleaseCapture函数,释放鼠标的俘获,同时 发送移动标题栏的消息,就可以实现窗口的拖动。
下面的例子实现了该功能。
>>步骤1----建立新工程,在窗体上放置CommandButton按钮。
>>步骤2----改变窗体的外观,使BorderStyle = 0(None)
>>步骤3----编写如下代码:

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_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF010&
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Private Sub Command1_Click()
End
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0
'SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
'上述两种方法都能实现该功能。
End Sub

>>步骤4----编译运行,在窗体上按下鼠标左键,是不是可以拖动了?按下Command1结束。

我的代码如下

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_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF010&
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Private Sub Forn_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Picture1.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub

这时,无论鼠标在窗体中怎么移动,Picture1就是不动,我想可能跟WM_NCLBUTTONDOWN有关吧,请问该如何更改,使Picture1跟随鼠标指针,或者用其他方法吧

搜索更多相关主题的帖子: Image控件 鼠标 指针 拖动 窗口 
2007-01-30 12:28
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Picture1.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub

需要在MoveDown事件中调用

天津网站建设 http://www./
2007-01-31 09:18
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 
要跟随指针直接移动控件就可以了,不明白你为什么要用API函数.

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Move X + 15, Y + 15
End Sub

天津网站建设 http://www./
2007-01-31 09:19
快速回复:[求助]怎样让一个Image控件跟随鼠标指针
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024315 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved