I would like something that I can use as follows
我想要一些我可以使用如下的东西
var msg = new NonStaticMessageBox();
if(msg.Show("MyMessage", "MyCaption", MessageBoxButtons.OkCancel) == DialogResult.Ok)
{....}
But specifically non-static (I need to pass a reference to it around) does anyone know if/where such an object exists?
但具体是非静态的(我需要传递一个引用)有没有人知道这样的对象是否存在?
6 个解决方案
#1
2
Such an object does not exist in the .net framework. You'll need to roll your own.
.net框架中不存在这样的对象。你需要自己动手。
#2
2
Looking at the comments. Encapsulation is your answer :)
看评论。封装是你的答案:)
#3
0
why do you need to pass a reference of it? you could just use MessageBox.Show and that's all? if you really need it you could make your own MessageBox class, something like:
为什么你需要传递它的参考?你可以使用MessageBox.Show,这就是全部?如果你真的需要它,你可以创建自己的MessageBox类,如:
public class MessageBox
{
private Form _messageForm = null;
public void Show(string title,...) {...}
}
or you could inherit MessageBox class and implement your own instance members... however I don't see any sense in this...
或者你可以继承MessageBox类并实现你自己的实例成员......但是我觉得这没有任何意义......
#4
0
Bear in mind that, at the end of the day, the S.W.F.MessageBox.Show() methods are all basically wrappers around the core Win32 MessageBox() API call. (Run mscorlib through Reflector; you'll see the "real" code in the private methods called ShowCore.)
请记住,在一天结束时,S.W.F.MessageBox.Show()方法基本上都是围绕核心Win32 MessageBox()API调用的包装器。 (通过Reflector运行mscorlib;您将在名为ShowCore的私有方法中看到“真实”代码。)
There is no provision (as far as I know) for caching the called MessageBox in Win32, therefore there is no way to do so in .NET.
没有规定(据我所知)在Win32中缓存被调用的MessageBox,因此在.NET中没有办法这样做。
I do have my own custom-built MessageBox class which I use -- although I did so not to cache it (in my usage scenarios in WinForms, the same MB is rarely used twice), but rather to provide a more detailed error message and information -- a header, a description, an ability to copy the message to the clipboard (it's usually the tool which notifies the user of an unhandled exception) and then the buttons.
我确实拥有自己定制的MessageBox类 - 虽然我这样做不是为了缓存它(在WinForms的使用场景中,相同的MB很少使用两次),而是提供更详细的错误消息和信息 - 标题,描述,将消息复制到剪贴板的能力(它通常是通知用户未处理的异常的工具)然后是按钮。
Your mileage may vary.
你的旅费可能会改变。
#5
0
You might want to have a look at the ExceptionMessageBox class that comes with SQL Server. It is in a self-contained assembly, but I'm not sure if you are allowed to redistribute it without SQL Server - you might need to check on this.
您可能希望查看SQL Server附带的ExceptionMessageBox类。它是一个独立的程序集,但我不确定你是否可以在没有SQL Server的情况下重新发布它 - 你可能需要检查它。
#6
0
You say
"This is obviously a simplification of my problem."
“这显然是我问题的简化。”
However your question doesn't reveal a problem we can solve without more information about intent.
但是,如果没有关于意图的更多信息,您的问题不能揭示我们可以解决的问题
Given that any form can be shown modally by calling ShowDialog and in the form returning DialogResult. I'm not seeing an issue here. You can pass whatever parameters you like into it, define the contents as you like, then call:
鉴于任何表单都可以通过调用ShowDialog以及返回DialogResult的形式以模态方式显示。我在这里没有看到问题。您可以将您喜欢的任何参数传递到其中,根据需要定义内容,然后调用:
MyFactory.GetMyCustomDialogWithInterfacesOrSomesuch myDialog = new ...
myDialog.ShowDialog() == DialogResult.Ok;
Because you're dealing with form and not MessageBox, it's not static so it's not an issue.
因为你正在处理表单而不是MessageBox,所以它不是静态的,所以它不是问题。
#1
2
Such an object does not exist in the .net framework. You'll need to roll your own.
.net框架中不存在这样的对象。你需要自己动手。
#2
2
Looking at the comments. Encapsulation is your answer :)
看评论。封装是你的答案:)
#3
0
why do you need to pass a reference of it? you could just use MessageBox.Show and that's all? if you really need it you could make your own MessageBox class, something like:
为什么你需要传递它的参考?你可以使用MessageBox.Show,这就是全部?如果你真的需要它,你可以创建自己的MessageBox类,如:
public class MessageBox
{
private Form _messageForm = null;
public void Show(string title,...) {...}
}
or you could inherit MessageBox class and implement your own instance members... however I don't see any sense in this...
或者你可以继承MessageBox类并实现你自己的实例成员......但是我觉得这没有任何意义......
#4
0
Bear in mind that, at the end of the day, the S.W.F.MessageBox.Show() methods are all basically wrappers around the core Win32 MessageBox() API call. (Run mscorlib through Reflector; you'll see the "real" code in the private methods called ShowCore.)
请记住,在一天结束时,S.W.F.MessageBox.Show()方法基本上都是围绕核心Win32 MessageBox()API调用的包装器。 (通过Reflector运行mscorlib;您将在名为ShowCore的私有方法中看到“真实”代码。)
There is no provision (as far as I know) for caching the called MessageBox in Win32, therefore there is no way to do so in .NET.
没有规定(据我所知)在Win32中缓存被调用的MessageBox,因此在.NET中没有办法这样做。
I do have my own custom-built MessageBox class which I use -- although I did so not to cache it (in my usage scenarios in WinForms, the same MB is rarely used twice), but rather to provide a more detailed error message and information -- a header, a description, an ability to copy the message to the clipboard (it's usually the tool which notifies the user of an unhandled exception) and then the buttons.
我确实拥有自己定制的MessageBox类 - 虽然我这样做不是为了缓存它(在WinForms的使用场景中,相同的MB很少使用两次),而是提供更详细的错误消息和信息 - 标题,描述,将消息复制到剪贴板的能力(它通常是通知用户未处理的异常的工具)然后是按钮。
Your mileage may vary.
你的旅费可能会改变。
#5
0
You might want to have a look at the ExceptionMessageBox class that comes with SQL Server. It is in a self-contained assembly, but I'm not sure if you are allowed to redistribute it without SQL Server - you might need to check on this.
您可能希望查看SQL Server附带的ExceptionMessageBox类。它是一个独立的程序集,但我不确定你是否可以在没有SQL Server的情况下重新发布它 - 你可能需要检查它。
#6
0
You say
"This is obviously a simplification of my problem."
“这显然是我问题的简化。”
However your question doesn't reveal a problem we can solve without more information about intent.
但是,如果没有关于意图的更多信息,您的问题不能揭示我们可以解决的问题
Given that any form can be shown modally by calling ShowDialog and in the form returning DialogResult. I'm not seeing an issue here. You can pass whatever parameters you like into it, define the contents as you like, then call:
鉴于任何表单都可以通过调用ShowDialog以及返回DialogResult的形式以模态方式显示。我在这里没有看到问题。您可以将您喜欢的任何参数传递到其中,根据需要定义内容,然后调用:
MyFactory.GetMyCustomDialogWithInterfacesOrSomesuch myDialog = new ...
myDialog.ShowDialog() == DialogResult.Ok;
Because you're dealing with form and not MessageBox, it's not static so it's not an issue.
因为你正在处理表单而不是MessageBox,所以它不是静态的,所以它不是问题。