C#文字跟随鼠标移动效果

来源:百度知道 编辑:UC知道 时间:2024/05/21 09:08:49
WinForm中,左击后鼠标右侧会出现文字,会跟随鼠标一起移动。放开后效果消失。如有回答可行者必有重赏!

算法出来了:

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
this.label2.Location = new Point(e.X + 10, e.Y);
this.label2.Text = "当前坐标:"+e.X + "," + e.Y;
}

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
this.label2.Visible = true;
}//判断是否为左键
}

private void Form1_MouseUp(object sender, MouseEventArgs e)
{
this.label2.Visible = false;
}
————————————————————————————
MouseMove:当鼠标在窗体移动的触发事件,跟e获取x,y的坐标

MouseDown:当按下鼠标的时候,判断是否为左键,如果true,就把label.visible=true;设置显示,

MouseUp:当放开(弹出)鼠标的时候,就直接设置Label为visible=false;o(∩_∩)o...够明白吧。。