我想在表单中显示一个带有 Ok 和 Detail 按钮的消息框。我已经为此功能编写了一些代码,但它也显示了一个取消按钮和详细信息它部分仅显示我用字符串编写的消息。代码是
var dialogTypeName = "System.Windows.Forms.PropertyGridInternal.GridErrorDlg";
var dialogType = typeof(M3Form).Assembly.GetType(dialogTypeName);
// Create dialog instance.
var dialog = (M3Form)Activator.CreateInstance(dialogType, new PropertyGrid());
// Populate relevant properties on the dialog instance.
dialog.Text = "Accknowledge Error";
dialogType.GetProperty("Details").SetValue(dialog, "Maximum length has been exceeded. Maximum = 50, Actual =" + txtName.Text.Length + "", null);
dialogType.GetProperty("Message").SetValue(dialog, "Maximum length has been exceeded. Maximum = 50, Actual =" + txtName.Text.Length + "", null);
// Display dialog.
var result = dialog.ShowDialog();
如何在详细信息部分仅显示确定按钮和详细信息按钮以及堆栈跟踪错误消息。
请您参考如下方法:
如果我理解正确,您想将 MessageBox 上的默认 OK 和 Cancel 按钮更改为 OK 和 Details。这需要太多的工作,如果不创建自己的 MessageBox 就无法轻松完成。
IMO 你最好创建一个看起来像 MessageBox 的新表单,并在每次需要显示消息时显示它。然后,您可以在显示 MessageBox Form 时使用 ShowDialog,使其成为类似于 MessageBox 的模态窗口。
