弹出窗口:
1 private void button1_Click(object sender, EventArgs e) 2 { 3 DialogResult dr = MessageBox.Show(this, "确定还是取消?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk); 4 if (dr == System.Windows.Forms.DialogResult.OK) 5 { 6 MessageBox.Show("你点击了确定"); 7 return; 8 9 } 10 if (dr == System.Windows.Forms.DialogResult.Cancel) 11 { 12 //点击右上角关闭,同样相当于点击了取消按钮。 13 MessageBox.Show("你点击了取消"); 14 return; 15 } 16 MessageBox.Show("你点击了关闭"); //这条语句怎么样都不执行 17 }
截图:
第二种样式:
1 private void button1_Click(object sender, EventArgs e) 2 { 3 DialogResult dr = MessageBox.Show(this, "确定还是取消?", "提示", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Asterisk); 4 if (dr == System.Windows.Forms.DialogResult.Abort) 5 { 6 MessageBox.Show("你点击了中止"); 7 return; 8 9 } 10 if (dr == System.Windows.Forms.DialogResult.Ignore) 11 { 12 13 MessageBox.Show("你点击了忽略"); 14 return; 15 } 16 if (dr == System.Windows.Forms.DialogResult.Retry) 17 { 18 19 MessageBox.Show("你点击了重试"); 20 return; 21 } 22 MessageBox.Show("你点击了关闭"); //这条语句怎么样都不执行 23 }
截图: