namespace ASillyDog { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.FormClosing += Form1_FormClosing; } private void Form1_Load(object sender, EventArgs e) { } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { // 检查是否是 Alt + F4 触发的关闭 if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt && (Control.ModifierKeys & Keys.F4) == Keys.F4) { // 取消关闭操作 e.Cancel = true; } else { // 处理其他用户关闭情况(如点击关闭按钮) e.Cancel = true; } } } private void button1_Click(object sender, EventArgs e) { // MessageBox.Show("按钮被点击了!"); } private void button2_Click(object sender, EventArgs e) { MessageBox.Show("你很有自知之明嘛~"); this.Close(); Application.Exit(); } private void button1_MouseEnter(object sender, EventArgs e) { Button button = (Button)sender; Random random = new Random(); int x = random.Next(0, this.ClientSize.Width - button.Width); int y = random.Next(0, this.ClientSize.Height - button.Height); button.Location = new Point(x, y); } } }