C# 鼠标点击按钮就可实现按钮的移动
2个回答
展开全部
在按钮的单击事件里面写:
//new一个随机的坐标
Random r = new Random();
//this.Size.Width 表示整个窗体的宽度
int X = r.Next(0, this.ClientSize.Width - button2.Size.Width);
int Y = r.Next(0,this.ClientSize.Height - button2.Size.Height);
//Location属性的结构
Point p = new Point(X,Y);
button2.Location = p;
//new一个随机的坐标
Random r = new Random();
//this.Size.Width 表示整个窗体的宽度
int X = r.Next(0, this.ClientSize.Width - button2.Size.Width);
int Y = r.Next(0,this.ClientSize.Height - button2.Size.Height);
//Location属性的结构
Point p = new Point(X,Y);
button2.Location = p;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询