首页 > 代码库 > 02 button的练习
02 button的练习
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("我也喜欢你!");
//if (this.button1.Text == "喜欢")
//{
// button2.Visible = false;
//}
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("我还不喜欢你呢!");
//if (this.button2.Text == "不喜欢")
//{
// button1.Visible = false;
//}
}
private void button2_MouseMove(object sender, MouseEventArgs e)
{
//Button2移动 不让鼠标点到
Random suiJi = new Random();
int x = suiJi.Next(0,this.Size.Width-this.button2.Size.Width);
int y = suiJi.Next(0,this.ClientSize.Height-this.button2.Size.Height);
Point p = new Point(x,y);
button2.Location = p;
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("做个测试吧!!"); //messagebox是一个类型 类型后面要跟.
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//窗体关闭事件的简单写法
DialogResult re = MessageBox.Show("确定关闭吗", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (re == DialogResult.No)
{
e.Cancel = true;
}
}
02 button的练习