集中应用程序的消息框处理
我想知道其他人如何处理尝试集中 MessageBox 函数调用。在过去(非.net语言),我不会将长文本嵌入到代码中,而是将系统和应用程序的基本“消息框”类型的消息放入数据库文件中,该文件将被“烧录”到可执行文件中,很像.Net 中的资源文件。当出现提示条件时,我只会调用类似
MBAnswer = MyApplication.CallMsgBox( IDUserCantDoThat ) 的
内容,然后在返回时检查 MBAnswer,例如是/否/取消或其他。
在数据库表中,我会包含诸如消息框标题是什么、将显示的按钮、实际消息、自动添加到后续标准注释(例如“如果发生这种情况,请联系服务台”)的特殊标志。 。该函数将使用所有适用的设置调用消息框,然后返回答案。这样做的最大好处是,可以在一个位置拥有所有消息的“上下文”,并且通过常量,可以更轻松地阅读将要呈现给用户的消息。
是否有人在 .Net 中有类似的系统来执行类似的方法,或者这在 .Net 环境中只是一个坏主意。
I'm wondering how others deal with trying to centralize MessageBox function calling. Instead of having long text embedded all over the place in code, in the past (non .net language), I would put system and application base "messagebox" type of messages into a database file which would be "burned" into the executable, much like a resource file in .Net. When a prompting condition would arise, I would just do call something like
MBAnswer = MyApplication.CallMsgBox( IDUserCantDoThat )
then check the MBAnswer upon return, such as a yes/no/cancel or whatever.
In the database table, I would have things like what the messagebox title would be, the buttons that would be shown, the actual message, a special flag that automatically tacked on a subsequent standard comment like "Please contact help desk if this happens.". The function would call the messagebox with all applicable settings and just return back the answer. The big benefits of this was, one location to have all the "context" of messages, and via constants, easier to read what message was going to be presented to the user.
Does anyone have a similar system in .Net to do a similar approach, or is this just a bad idea in the .Net environment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们曾经使用模块(VB)来处理集中式消息。我们有一个包含所有消息的模块,我们在代码中调用它。这样做是为了我们可以在一处更改消息(由于业务需要),并且它会在各处得到反映。而且,在一个文件中处理更改(而不是在多个文件中更改消息)也很容易。我们还向业务分析师 (VSS) 开放了该文件,以便他们可以更改它。我认为如果它涉及模块或静态类,这不是一个坏主意,但从数据库获取它可能有点过分了。
华泰
We used to handle centralized messages with Modules (VB). We had one module with all messages and we call that in our code. This was done so that we change the message in one place (due to business needs) and it gets reflected everywhere. And it was also easy to handle change in one file instead of multiple files to change the message. Also we opened up that file to Business Analysts (VSS) so that they can change it. I don't think it is a bad idea if it involves modules or static class but it might be a overkill to fetch it from DB.
HTH
您可以使用资源文件将所有文本导出到那里(也有点本地化功能)。 Resharper 5.0 确实有助于突出显示可以移动到资源的文本。
通常它看起来像这样:
MessageBox.Show(error.ToString(), "Error with extract");
MessageBox.Show(error.ToString(), Resources.MainForm_ExtractArchive_Error_with_extraction);
最重要的是,它可以轻松地将内容翻译成其他语言,并将
MessageBox
的文本保留在单独的Resource
中。当然,Resharper 会为您完成这一切,因此无需输入那么多:-)You could use resource files to export all text into there (kinda localization feature as well). Resharper 5.0 really helps in that highlighting text that can be moved to resource.
Usually it looks like this:
MessageBox.Show(error.ToString(), "Error with extraction");
MessageBox.Show(error.ToString(), Resources.MainForm_ExtractArchive_Error_with_extraction);
Best of all it makes it easy to translate stuff to other languages as well as keeping text for
MessageBox
in separateResource
. Of course Resharper does it all for you so no need to type that much :-)我想你可以使用哈希表来做类似的事情,这可以在:
为了保持全局可访问性,我正在考虑在一个类中使用几个函数来保存哈希表来获取/设置某个函数。
现在让我们看看。
或者类似的东西,您可以在哈希表中保留多个不同的信息,然后也在函数中组成消息框..而不是仅仅返回消息框内容的字符串...
但使用它会非常简单。
在程序加载时调用这样的函数。
例如,然后。
我将其放在一个新类中,而不是直接使用 HashTable get/set 方法,因为这为自定义留出了空间,因此可以在 get 中创建消息框,并且可以在集合中存储多于 1 条信息来处理消息框标题、按钮类型、内容等。
I suppose you could use a HashTable to do something similar like this, this can be found in:
To keep it globally accessable i was thinking a couple of functions in a class holding the hashtable to get/set a certain one.
lets see now.
or something like that, you could keep multiple different information in the hashtable and subsequently compose the messagebox in the function too.. instead of just returning the string for the messagebox contents...
but to use this it would be quite simple.
call a function like this on program load.
for example, and then.
i put this in a new class instead of using the HashTable get/set methods direct because this leaves room for customization so the messagebox could be created in the get, and more than 1 piece of information could be stored in the set to handle messagebox title, buttontype, content, etc etc.