集中应用程序的消息框处理

发布于 2024-08-29 08:03:16 字数 475 浏览 4 评论 0原文

我想知道其他人如何处理尝试集中 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生来就爱笑 2024-09-05 08:03:16

我们曾经使用模块(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

香草可樂 2024-09-05 08:03:16

您可以使用资源文件将所有文本导出到那里(也有点本地化功能)。 Resharper 5.0 确实有助于突出显示可以移动到资源的文本。

通常它看起来像这样:

  1. 之前: MessageBox.Show(error.ToString(), "Error with extract");
  2. 建议:本地化字符串“Error with extract”
  3. 右键单击​​ 移动到资源
  4. 选择资源文件并名称(MainForm_ExtractArchive_Error_with_extraction),还要选中复选框在类中查找相同的项目...这样调用
  5. 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:

  1. Before: MessageBox.Show(error.ToString(), "Error with extraction");
  2. Suggestion: Localizable string "Error with extraction"
  3. Right click Move to Resource
  4. Choose resource file and name (MainForm_ExtractArchive_Error_with_extraction), also check checkbox Find identical items in class ...
  5. Call it like this 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 separate Resource. Of course Resharper does it all for you so no need to type that much :-)

樱花坊 2024-09-05 08:03:16

我想你可以使用哈希表来做类似的事情,这可以在:

using System.Collections;

为了保持全局可访问性,我正在考虑在一个类中使用几个函数来保存哈希表来获取/设置某个函数。
现在让我们看看。

public class MessageBoxStore
{
    private HashTable stock;
    public string Get(string msg)
    {
        if (stock.ContainsKey(msg))
            return stock[msg];
        else
            return string.Empty;
    }

    public string Set(string msg, string msgcontent)
    {
        stock[msg] = msgcontent;
    }
}

或者类似的东西,您可以在哈希表中保留多个不同的信息,然后也在函数中组成消息框..而不是仅仅返回消息框内容的字符串...
但使用它会非常简单。

在程序加载时调用这样的函数。

public LoadErrorMessages()
{
    storeClass = new MessageBoxStore();
    storeClass.Set("UserCantDoThat", "Invalid action. Please confirm your action and try again");
}

例如,然后。

MessageBox.Show(storeClass.Get("UserCantDoThat"));

我将其放在一个新类中,而不是直接使用 HashTable get/set 方法,因为这为自定义留出了空间,因此可以在 get 中创建消息框,并且可以在集合中存储多于 1 条信息来处理消息框标题、按钮类型、内容等。

I suppose you could use a HashTable to do something similar like this, this can be found in:

using System.Collections;

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.

public class MessageBoxStore
{
    private HashTable stock;
    public string Get(string msg)
    {
        if (stock.ContainsKey(msg))
            return stock[msg];
        else
            return string.Empty;
    }

    public string Set(string msg, string msgcontent)
    {
        stock[msg] = msgcontent;
    }
}

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.

public LoadErrorMessages()
{
    storeClass = new MessageBoxStore();
    storeClass.Set("UserCantDoThat", "Invalid action. Please confirm your action and try again");
}

for example, and then.

MessageBox.Show(storeClass.Get("UserCantDoThat"));

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文