怎样获得鼠标位置?

qyly78 2003-06-16 07:27:51
在winforms程序中我不能获得鼠标在form以外时的位置(相当于对话框程序).这个问题是否根本无法解决?还是有什么更好的解决方案?
  请各位多加指教!
...全文
27 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
qyly78 2003-06-18
  • 打赏
  • 举报
回复
非常感谢gujianxin(木头象)!
你的方法非常正确.
qyly78 2003-06-18
  • 打赏
  • 举报
回复
非常感谢gujianxin(木头象)!
你的方法非常正确.
gujianxin 2003-06-17
  • 打赏
  • 举报
回复
好像少拷了一行
private void button1_Click(object sender, System.EventArgs e)
{
MOUSE_POSITION p;
p.X = 0;
p.Y = 0;
bool b = GetCursorPos(ref p);
int x= System.Windows.Forms.Form.MousePosition.X;
int y= System.Windows.Forms.Form.MousePosition.Y;

if((p.X == System.Windows.Forms.Form.MousePosition.X) && (p.Y ==System.Windows.Forms.Form.MousePosition.Y))
MessageBox.Show("the same point");

}
gujianxin 2003-06-17
  • 打赏
  • 举报
回复
//声明结构
public struct MOUSE_POSITION
{
public int X;
public int Y;
}
//声明API
[DllImport("user32")]
static extern bool GetCursorPos(ref MOUSE_POSITION p);
//调用
private void button1_Click(object sender, System.EventArgs e)
{
p.X = 0;
p.Y = 0;
bool b = GetCursorPos(ref p);

}
qyly78 2003-06-17
  • 打赏
  • 举报
回复
请各位帮忙?
qyly78 2003-06-17
  • 打赏
  • 举报
回复
也许是我没说清楚,我想在基于Winform的程序中获得鼠标在屏幕上的位置.当鼠标在对话框内时可以获得.但是当鼠标在对话框外时怎么办?如果Windows API 函数可行  GetCursorPos()函数应该具体如何使用?
CaffeMocha 2003-06-16
  • 打赏
  • 举报
回复
//鼠标相对Screen的位置
System.Windows.Forms.Form.MousePosition.X
System.Windows.Forms.Form.MousePosition.Y
shuker 2003-06-16
  • 打赏
  • 举报
回复
Control.MousePosition
或者API: GetCursorPos()
TheAres 2003-06-16
  • 打赏
  • 举报
回复
Control.MousePosition是一个Point,存放着鼠标的位置,直接调用就可以。

比如:
Point p = Control.MousePosition;
qyly78 2003-06-16
  • 打赏
  • 举报
回复
请大家能讲具体一点
wangjs720 2003-06-16
  • 打赏
  • 举报
回复
可以用API: GetCursorPos()
TheAres 2003-06-16
  • 打赏
  • 举报
回复
Control.MousePosition就是。
lovered 2003-06-16
  • 打赏
  • 举报
回复
[v]
做个记号 up一下

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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