我怎样才能显示在的WinForms细节的消息框? [英] How can I show a message box with details in WinForms?

查看:205
本文介绍了我怎样才能显示在的WinForms细节的消息框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚才我注意到,Visual Studio中显示细节一个消息框,当一个属性设置为无效值。例如:

Just now I noticed that Visual Studio shows a message box with details when a property is set to an invalid value. For example:

是否有可能使这一类型的消息框的WinForms?

Is it possible to make this type of message box in WinForms?

我曾尝试以下code:

I have tried the following code:

MessageBox.Show("Error in Division Fill.\n" + ex.Message,
                "Information",            
                MessageBoxButtons.OK,
                MessageBoxIcon.Information,
                MessageBoxOptions.RightAlign);

但是,这将产生以下错误:

But this produced the following error:

错误24的最佳重载方法匹配'System.Windows.Forms.MessageBox.Show(字符串,字符串,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon,System.Windows.Forms.MessageBoxDefaultButton) 有一些无效的参数

Error 24 The best overloaded method match for 'System.Windows.Forms.MessageBox.Show(string, string, System.Windows.Forms.MessageBoxButtons, System.Windows.Forms.MessageBoxIcon, System.Windows.Forms.MessageBoxDefaultButton)' has some invalid arguments

G:\ Jagadeeswaran \ 11月17日\ MCS-SPS学校\ MCS-SPS学校\证书\ Transfer.cs 164 21 MCS-SPS学校

G:\Jagadeeswaran\Nov 17\MCS-SPS School\MCS-SPS School\Certificate\Transfer.cs 164 21 MCS-SPS School

我怎样才能解决这个错误,并得到显示更多细节的消息框?

How can I fix this error and get a message box that shows additional details?

推荐答案

正如其他人所指出的那样,你应该写与所需功能的自定义对话框。关于这个帮助,你可以看看所用的的PropertyGrid 此对话框(或许还有一个反编译器)的实际执行情况,这是由于.NET 4.0, System.Windows.Forms.PropertyGridInternal.GridErrorDlg 类型,内部的 System.Windows.Forms的组件。

As others have pointed out, you should write a custom dialog with the desired features. For help on this, you can look at the actual implementation used by the PropertyGrid for this dialog (perhaps with a decompiler) , which is, as of .NET 4.0, the System.Windows.Forms.PropertyGridInternal.GridErrorDlg type, internal to the System.Windows.Forms assembly.

我的真正的不会推荐它(可能在将来的版本破解),但如果你感觉真的很懒惰,你可以使用反射直接使用此内部类型。

I really wouldn't recommend it (could break in a future release), but if you're feeling really lazy, you can directly use this internal type using reflection.

// Get reference to the dialog type.
var dialogTypeName = "System.Windows.Forms.PropertyGridInternal.GridErrorDlg";
var dialogType = typeof(Form).Assembly.GetType(dialogTypeName);

// Create dialog instance.
var dialog = (Form)Activator.CreateInstance(dialogType, new PropertyGrid());

// Populate relevant properties on the dialog instance.
dialog.Text = "Sample Title";
dialogType.GetProperty("Details").SetValue(dialog, "Sample Details", null);
dialogType.GetProperty("Message").SetValue(dialog, "Sample Message", null);

// Display dialog.
var result = dialog.ShowDialog();

结果

这篇关于我怎样才能显示在的WinForms细节的消息框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆