鼠标悬停时怎么获得鼠标的位置?(很急!)
protected override void OnMouseHover(System.EventArgs e)
{
if((Cursor.Position.X>70)&&(Cursor.Position.X<130))
{
MessageBox.Show("dzfc!");
}
if((Cursor.Position.X>=130)&&(Cursor.Position.X<190))
{
MessageBox.Show("duan!");
}
if((Cursor.Position.X>=190)&&(Cursor.Position.X<310))
{
MessageBox.Show("zuanshi!");
}
}
我需要知道鼠标悬停时候它的位置才能区分它在那个区域
上面的代码不行,鼠标停在那个区域它也不弹出对话框,非要点击下鼠标才开始运行
谁能告诉我上面的有什么问题或者其他获得鼠标位置的方法
问题点数:100、回复次数:4Top
1 楼tylike(http://www.admiralcn.com)回复于 2005-08-01 21:02:57 得分 10
try
Control.MousePosition.X
Control.MousePosition.YTop
2 楼tylike(http://www.admiralcn.com)回复于 2005-08-01 21:04:22 得分 20
你不如再你现在的近件上再画一个panel,然后,把panel大小调整成你要的大小,然后,在panel的mousehover事件中写你的代码Top
3 楼wuyi8808(空间/IV)回复于 2005-08-01 21:20:43 得分 50
// 使用 OnMouseMove 就没问题了:
using System.Windows.Forms;
class Test : Form
{
protected override void OnMouseMove(MouseEventArgs e)
{
if ((e.X > 70) && (e.X < 130))
{
MessageBox.Show("dzfc!");
}
if ((e.X >= 130) && (e.X < 190))
{
MessageBox.Show("duan!");
}
if ((e.X >= 190) && (e.X < 310))
{
MessageBox.Show("zuanshi!");
}
}
static void Main()
{
Application.Run(new Test());
}
}
Top
4 楼wuyi8808(空间/IV)回复于 2005-08-01 21:38:29 得分 20
// 这样直接就可以得到鼠标移动时的坐标:
using System.Windows.Forms;
class Test : Form
{
Label lbl = new Label();
Test()
{
lbl.Parent = this;
lbl.AutoSize = true;
}
protected override void OnMouseMove(MouseEventArgs e)
{
lbl.Text = string.Format("X:{0,-4} Y:{1}", e.X, e.Y);
}
static void Main()
{
Application.Run(new Test());
}
}
Top




