public partial class Form1 : Form
{
public Form3()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
MessageBox.Show("你真厉害!");
}
private void label1_MouseEnter(object sender, EventArgs e)
{
/*ClientSize是客户区大小,也就是内部真正可用的"净面积",
如果直接使用this.Width可能会造成label组件"消失"在窗口
(实际在最下侧或者最右侧)
*/
int x = this.ClientSize.Width;
int y = this.ClientSize.Height;
Random r = new Random();
label1.Location = new Point(r.Next(x - this.label1.Width), r.Next(y - this.label1.Height));
}
}