image.png

    1. public partial class Form1 : Form
    2. {
    3. public Form1()
    4. {
    5. InitializeComponent();
    6. }
    7. /// <summary>
    8. /// 当鼠标进入按钮的可见部分的时候,给按钮一个新的坐标
    9. /// </summary>
    10. /// <param name="sender"></param>
    11. /// <param name="e"></param>
    12. private void Button2_MouseEnter(object sender, EventArgs e)
    13. {
    14. //给按钮一个新的坐标
    15. //这个按钮活动的最大宽度就是:窗体的宽度减去按钮的宽度
    16. int x = this.ClientSize.Width - button1.Width; //this.Width 这样窗口变大后就不是这个值了
    17. int y = this.ClientSize.Height - button1.Height;
    18. Random r = new Random();
    19. //要给按钮一个随机坐标
    20. button2.Location = new Point(r.Next(0, x + 1), r.Next(0, y + 1));
    21. }
    22. private void Button1_Click(object sender, EventArgs e)
    23. {
    24. for (int i = 1000; i >= 0; i--)
    25. {
    26. MessageBox.Show("再点" + i + "次,给我证明你有多爱我");
    27. }
    28. MessageBox.Show("傻逼我爱你~");
    29. this.Close();//关闭主窗口
    30. }
    31. private void Button2_Click(object sender, EventArgs e)
    32. {
    33. MessageBox.Show("小湘,你最好承认你是点着玩的。");
    34. MessageBox.Show("主动给我承认!");
    35. MessageBox.Show("给我承认!");
    36. MessageBox.Show("承认!");
    37. MessageBox.Show("!");
    38. this.Close();
    39. }
    40. }