请高手指教
static void Main() //入口函数,启动Form//{
Application.Run(new Form1());
}
private void btn_catchMe_Click(object sender, System.EventArgs e)//Click事件//
{
MessageBox.Show("抓到我了,算你聪明!", "抓到了");//给出一个消息//
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)//鼠表在form上移动事件//
{
int border = 50;
int x = e.X;
int y = e.Y;//鼠表的x坐标,y坐标//
int left = btn_catchMe.Left;
int right = btn_catchMe.Right;
int top = btn_catchMe.Top;
int bottom = btn_catchMe.Bottom;//上下左右的位置//
/* 鼠标到按钮附近(10个象素) */
if( x > left - border && x < right + border && y > top - border && y < bottom + border)
{
btn_catchMe.Top += (y > top ? -20 : 20);
if(btn_catchMe.Top > Form1.ActiveForm.Size.Height || btn_catchMe.Bottom < 0)
{
btn_catchMe.Top = Form1.ActiveForm.Size.Height/2;
}
btn_catchMe.Left += (x > left ? -20 : 20);
if(btn_catchMe.Left > Form1.ActiveForm.Size.Width || btn_catchMe.Right < 0)
{
btn_catchMe.Left = Form1.ActiveForm.Size.Width/2;
}
}
string prompt = "Mouse(" + x.ToString() + "," + y.ToString() + ")";
prompt += " Button(" + left.ToString() + "," + top.ToString() + ")(" + right.ToString() + "," + bottom.ToString() + ")";
prompt += " ^_^ 抓不到哦";
statusBar1.Text = prompt;
}
private void statusBar1_PanelClick(object sender, StatusBarPanelClickEventArgs e)
{
}
}
}
是怎么实现按钮随鼠标运动的?鼠标会不会点到按钮?