紧急求助,鼠标小手问题 我的form里面有个panel,我希望实现的功能是当鼠标点击左键的时候鼠标变成小手的样子并且移动鼠标可以移动panel,就像看图片那种功能。请教大侠们,我这个是写在那个方法里哦??是写在MouseDown事件里还是写在MouseMove事件里面哦??望解答,在此先谢谢先。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在MouseDown事件里把Cursor属性设为Hand,出来的效果就是小手 你点form 然后在form属性里头有个cursor 把它选成hand 就行了 在form的mousemove消息里面操作mousemove要检查mousedown是否按下 还是检查mouseup是否弹起了 做一个全局private int x = 0;private int y = 0;然后你应该在鼠标MouseDown里写 this.Cursor = Cursors.Hand x = e.X;y = e.Y;然后在MouseMove里写if(this.Cursor == Cursors.Hand ){ //变换坐标 int distanceX = e.X - panel.location.X; int distanceY = e.Y - panel.location.Y; panel.location = new Point(panel.Location.X + x, panel.Location.Y + y);} 在MouseDown事件里设置鼠标样式,在mousemove事件里获取鼠标位置,设置panel位置this.MouseDown += new System.Windows.Forms.MouseEventHandler(MyMouseDown); this.MouseLeave += new System.EventHandler(MyMouseLeave); this.MouseMove += new System.Windows.Forms.MouseEventHandler(MyMouseMove);private void MyMouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { int x = e.X; }private void MyMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { } 我写错了 应该这样//变换坐标 int distanceX = e.X - x; int distanceY = e.Y - y; panel.location = new Point(panel.Location.X + distanceX , panel.Location.Y + distanceY ); //变换坐标 int distanceX = e.X - x; int distanceY = e.Y - y; panel.location = new Point(panel.Location.X + distanceX , panel.Location.Y + distanceY ); 再加个x = e.X;y = e.Y;这样就好了 做一个全局 private int x = 0; private int y = 0; 然后你应该在鼠标MouseDown里写 this.Cursor = Cursors.Hand x = e.X; y = e.Y; 然后在MouseMove里写 if(this.Cursor == Cursors.Hand ) { //变换坐标 int distanceX = e.X - x; int distanceY = e.Y - y; panel.location = new Point(panel.Location.X + distanceX , panel.Location.Y + distanceY ); x = e.X; y = e.Y; } private void panel1_MouseDown(object sender, MouseEventArgs e) { panel1.MouseMove += new MouseEventHandler(panel1_MouseMove); panel1.Cursor = Cursors.Hand; } void panel1_MouseMove(object sender, MouseEventArgs e) { //这里改变你panel的位置 } private void panel1_MouseUp(object sender, MouseEventArgs e) { panel1.MouseMove -= new MouseEventHandler(panel1_MouseMove); panel1.Cursor = Cursors.Default; } 如果你想鼠标移到那panel上,光标就变,那这个换到panel1.Cursor 放到 MouseEnter 和MouseLeave里面改变。 利用Aforge.Net 调用多个摄像头的一个简单问题 多个不规则html表格添加到Excel每个工作表中。 请教给位大神!!! 《《《《《datagridview控件问题》》》》》 两个DataSet之间的操作! localhost站點 被cookie 阻止 如何改变TextBox为只读,但不改变背景色? 求C#制作学生成绩管理系统 源码 C# 2.0 中怎么监视剪贴板的动作???? 问WinForm下DataGrid怎样刷新数据的问题!!!! `急`求助打印高手 解惑,关于数据类型,在线等...
mousemove要检查mousedown是否按下 还是检查mouseup是否弹起了
private int x = 0;
private int y = 0;
然后你应该在鼠标MouseDown里写
this.Cursor = Cursors.Hand
x = e.X;
y = e.Y;然后在MouseMove里写
if(this.Cursor == Cursors.Hand )
{
//变换坐标
int distanceX = e.X - panel.location.X;
int distanceY = e.Y - panel.location.Y;
panel.location = new Point(panel.Location.X + x, panel.Location.Y + y);
}
this.MouseDown += new System.Windows.Forms.MouseEventHandler(MyMouseDown);
this.MouseLeave += new System.EventHandler(MyMouseLeave);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(MyMouseMove);
private void MyMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int x = e.X;
}
private void MyMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
}
//变换坐标
int distanceX = e.X - x;
int distanceY = e.Y - y;
panel.location = new Point(panel.Location.X + distanceX , panel.Location.Y + distanceY );
int distanceX = e.X - x;
int distanceY = e.Y - y;
panel.location = new Point(panel.Location.X + distanceX , panel.Location.Y + distanceY ); 再加个
x = e.X;
y = e.Y;
这样就好了
做一个全局
private int x = 0;
private int y = 0;
然后你应该在鼠标MouseDown里写
this.Cursor = Cursors.Hand
x = e.X;
y = e.Y; 然后在MouseMove里写
if(this.Cursor == Cursors.Hand )
{
//变换坐标
int distanceX = e.X - x;
int distanceY = e.Y - y;
panel.location = new Point(panel.Location.X + distanceX , panel.Location.Y + distanceY ); x = e.X;
y = e.Y;
}
{
panel1.MouseMove += new MouseEventHandler(panel1_MouseMove);
panel1.Cursor = Cursors.Hand;
} void panel1_MouseMove(object sender, MouseEventArgs e)
{
//这里改变你panel的位置
} private void panel1_MouseUp(object sender, MouseEventArgs e)
{
panel1.MouseMove -= new MouseEventHandler(panel1_MouseMove);
panel1.Cursor = Cursors.Default;
}
如果你想鼠标移到那panel上,光标就变,那这个换到panel1.Cursor 放到 MouseEnter 和MouseLeave里面改变。