I want to display a link to help in a message box. By default the text is displayed as a non-selectable string.
I want to display a link to help in a message box. By default the text is displayed as a non-selectable string.
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.