有没有必要做MessageBox.Show(这个,“消息”)vs MessageBox.Show(“Message”)

时间:2014-04-04 15:34:01

标签: c# winforms

执行MessageBox.Show(this, "Message") vs MessageBox.Show("Message")是否有意义?

取消对话框默认为this作为所有者?

更新:我的用例是通过win表单中的方法正常调用它。

1 个答案:

答案 0 :(得分:2)

MessageBox.Show(string text)的实现方式如下:

 public static DialogResult Show(string text) {
            return ShowCore(null, text, String.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, 0, false);
    }

ShowCore中有一个类似的检查:

if (owner == null) {
    handle = UnsafeNativeMethods.GetActiveWindow();
}
else {
    handle = Control.GetSafeHandle(owner);
}

来自:Reference Source - Microsoft

所以你的电话都会做同样的事情。由于this将是ActiveWindow。

相关问题