C#的DialogResult属性

来源:百度知道 编辑:UC知道 时间:2024/05/10 06:21:51
我设置了按钮的DialogResult属性,运行时,我点击按钮可是对话框并不关闭,书上说会关闭的啊。为什么会这样子啊?谢谢

???你不会在调试吧???再试一次.

private void InitializeMyButton()
{
// Create and initialize a Button.
Button button1 = new Button();

// Set the button to return a value of OK when clicked.
button1.DialogResult = DialogResult.OK;

// Add the button to the form.
Controls.Add(button1);
}

if (MessageBox.Show("是否关闭?", "信息", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
this.Close();
}