public partial class Form1 : Form{public Form1(){InitializeComponent();}/// <summary>/// 当鼠标进入按钮的可见部分的时候,给按钮一个新的坐标/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void Button2_MouseEnter(object sender, EventArgs e){//给按钮一个新的坐标//这个按钮活动的最大宽度就是:窗体的宽度减去按钮的宽度int x = this.ClientSize.Width - button1.Width; //this.Width 这样窗口变大后就不是这个值了int y = this.ClientSize.Height - button1.Height;Random r = new Random();//要给按钮一个随机坐标button2.Location = new Point(r.Next(0, x + 1), r.Next(0, y + 1));}private void Button1_Click(object sender, EventArgs e){for (int i = 1000; i >= 0; i--){MessageBox.Show("再点" + i + "次,给我证明你有多爱我");}MessageBox.Show("傻逼我爱你~");this.Close();//关闭主窗口}private void Button2_Click(object sender, EventArgs e){MessageBox.Show("小湘,你最好承认你是点着玩的。");MessageBox.Show("主动给我承认!");MessageBox.Show("给我承认!");MessageBox.Show("承认!");MessageBox.Show("!");this.Close();}}
