使用C#实现鼠标进入按键范围后按键自动窗体内位置移动

时间:2017-07-30 12:25:21   收藏:0   阅读:310

新建winform窗体程序

技术分享

添加button控件

 技术分享

在事件中选择 MouseEnter

技术分享

 

代码如下

private void button_MouseEnter(object sender, EventArgs e)

{

//给按钮一个新的坐标

//这个按钮活动的最大宽度就是 窗体的宽度减去按钮的宽度

  int x = this.ClientSize.Width - button.Width;
  int y = this.ClientSize.Height - button.Height;
  Random r = new Random();
  button.Location = new Point(r.Next(0, x + 1), r.Next(0, y + 1));
}

 

原文:http://www.cnblogs.com/siyuanshuo/p/7258538.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!