Winform 消息框中可点击的 URL?

发布于 2024-08-14 03:06:08 字数 41 浏览 3 评论 0原文

我想在消息框中显示帮助链接。默认情况下,文本显示为不可选择的字符串。

I want to display a link to help in a message box. By default the text is displayed as a non-selectable string.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

邮友 2024-08-21 03:06:08

一种选择是在消息框中显示 url 以及一条消息,并提供帮助按钮,将您带到该 url:

MessageBox.Show(
    "test message",
    "caption",
    MessageBoxButtons.YesNo,
    MessageBoxIcon.Information,
    MessageBoxDefaultButton.Button1,
    0, '0 is default otherwise use MessageBoxOptions Enum
    "http://google.com",
    "keyword")

重要的是要注意此代码不能出现在表单的加载事件中,“帮助”按钮不会打开该链接。

One option is display the url in the message box, along with a message and provide the help button that takes you to that url:

MessageBox.Show(
    "test message",
    "caption",
    MessageBoxButtons.YesNo,
    MessageBoxIcon.Information,
    MessageBoxDefaultButton.Button1,
    0, '0 is default otherwise use MessageBoxOptions Enum
    "http://google.com",
    "keyword")

Important to note this code cannot be in the load event of the form, the Help button will not open the link.

就是爱搞怪 2024-08-21 03:06:08

You can use the LinkLabel control on your own Form for this. Unfortunately, the MessageBox form cannot be customized in this way, so you would need to create your own Form to mimic the MessageBox for your purposes.

凉宸 2024-08-21 03:06:08

MessageBox 不会这样做。您需要使用TaskDialog(在Vista 中引入)或创建您自己的对话框。

--编辑--
有多种方法可以在 XP 上伪造任务对话框。我过去使用过 CodeProject.com 上的几篇文章。

MessageBox won't do that. You'll either need to use the TaskDialog (introduced in Vista) or create your own dialog.

--Edit--
There are ways to fake the task dialog on XP. There are a few articles on CodeProject.com that I've used in the past.

说不完的你爱 2024-08-21 03:06:08

您必须创建自己的表单,而不是内置的 MessageBox,并且可以在其上使用 LinkLabel

然而,在内置的 MessageBox 上,按钮之间可以显示帮助按钮。

You have to create your own form, instead of the built-in MessageBox, and you can use a LinkLabel on it.

However on the built-in MessageBox a Help button could be displayed among the buttons.

新一帅帅 2024-08-21 03:06:08

您可以将一些自定义代码与 LinkLabel 一起使用,如下所示:

        if (hyperLinks != null)
        {
            foreach (var link in hyperLinks)
            {
                var linkLabel = new LinkLabel();
                linkLabel.Text = link;
                linkLabel.Width = WhateverParentPanelYouHave.Width;
                linkLabel.Click += LabelClicked;
                WhateverParentPanelYouHave.Controls.Add(linkLabel);
             }
         }

其中 hyperLinks 是链接的字符串列表。

然后对于您的 LabelClicked 处理程序:

      private async void LabelClicked(object sender, EventArgs e)
      {
        var linkLabel = (LinkLabel) sender;
        var path = linkLabel.Text;
        try
        {
            await Task.Run(() => Process.Start($@"{path}"));
        }
        catch (Exception ex)
        {
            MessageBox.ShowMessage(ex.Message, @"An Error Has Occurred");
        }

      }

请记住,这是您自己的表单,其中添加了 LinkLabel 控件。您必须继承 Form 并使用 ShowDialog() 方法来显示添加了所有控件的表单。

You could use some custom code with LinkLabel like this:

        if (hyperLinks != null)
        {
            foreach (var link in hyperLinks)
            {
                var linkLabel = new LinkLabel();
                linkLabel.Text = link;
                linkLabel.Width = WhateverParentPanelYouHave.Width;
                linkLabel.Click += LabelClicked;
                WhateverParentPanelYouHave.Controls.Add(linkLabel);
             }
         }

Where hyperLinks is a list of strings for your links.

Then for your LabelClicked handler:

      private async void LabelClicked(object sender, EventArgs e)
      {
        var linkLabel = (LinkLabel) sender;
        var path = linkLabel.Text;
        try
        {
            await Task.Run(() => Process.Start($@"{path}"));
        }
        catch (Exception ex)
        {
            MessageBox.ShowMessage(ex.Message, @"An Error Has Occurred");
        }

      }

Keep in mind, this is your own form with the LinkLabel control added to it. You'll have to inherit from Form and use the ShowDialog() method to display your form with all your controls added to it.

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