vb.net Winform 消息框中的可点击 URL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1833747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Clickable URL in a Winform Message Box?
提问by Jeff
I want to display a link to help in a message box. By default the text is displayed as a non-selectable string.
我想在消息框中显示帮助链接。默认情况下,文本显示为不可选择的字符串。
回答by schar
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:
一种选择是在消息框中显示 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")
Important to note this code cannot be in the load event of the form, the Help button will not open the link.
重要的是要注意这个代码不能在表单的加载事件中,帮助按钮不会打开链接。
回答by Jeff Yates
回答by Brad Bruce
MessageBox won't do that. You'll either need to use the TaskDialog (introduced in Vista) or create your own dialog.
MessageBox 不会这样做。您将需要使用 TaskDialog(在 Vista 中引入)或创建您自己的对话框。
--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.
--编辑--
有多种方法可以在 XP 上伪造任务对话框。CodeProject.com 上有几篇我过去使用过的文章。
回答by treaschf
You have to create your own form, instead of the built-in MessageBox, and you can use a LinkLabel
on it.
您必须创建自己的表单,而不是内置的 MessageBox,并且可以LinkLabel
在其上使用 a 。
However on the built-in MessageBox a Help button could be displayed among the buttons.
但是,在内置的 MessageBox 上,可以在按钮之间显示帮助按钮。
回答by Prasanth Louis
You could use some custom code with LinkLabel
like this:
您可以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);
}
}
Where hyperLinks
is a list of strings for your links.
hyperLinks
链接的字符串列表在哪里。
Then for your LabelClicked
handler:
然后对于您的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");
}
}
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.
请记住,这是您自己的表单,其中LinkLabel
添加了控件。您必须继承Form
并使用该ShowDialog()
方法来显示添加了所有控件的表单。