怎样使按钮在窗体里四处游动
就是点不到咯! private void button1_MouseEnter(object sender, EventArgs e)
{
Random r = new Random();
this.button1.Left = r.Next();
if (button1.Left > this.Left)
{
this.button1.Left = r.Next();
}
this.button1.Right = r.Next();
}
没有达到我的要求,这个只触发了一次是不是我的事件写错了?
给Right复值是报
错误 1 无法对属性或索引器“System.Windows.Forms.Control.Right”赋值 -- 它是只读的
请写点代码给与支持!
叩谢!
就是点不到咯! private void button1_MouseEnter(object sender, EventArgs e)
{
Random r = new Random();
this.button1.Left = r.Next();
if (button1.Left > this.Left)
{
this.button1.Left = r.Next();
}
this.button1.Right = r.Next();
}
没有达到我的要求,这个只触发了一次是不是我的事件写错了?
给Right复值是报
错误 1 无法对属性或索引器“System.Windows.Forms.Control.Right”赋值 -- 它是只读的
请写点代码给与支持!
叩谢!
{
Random rnd = new Random ();
button1.Location = new Point(rnd.Next(0, this.Width-button1 .Width ), rnd.Next(0, this.Height-button1 .Height ));
}这样就行了
{
Random rnd = new Random();
button1.Left = rnd.Next(0, this.Width - button1.Width);
button1.Top = rnd.Next(0, this.Height - this.Location.Y);
}
Random rnd = new Random();
button1.Left = rnd.Next(0, this.Width - button1.Width);
button1.Top = rnd.Next(0,this.ClientRectangle.Height -button1 .Height );