我可以在Visual Studios上使用LinkLabel链接到Windows窗体吗?

问题描述:

我一直在谷歌上查找如何使用linklabel链接到Windows窗体。我遇到的所有教程只链接到URL或本地磁盘。有帮助吗?我不想使用按钮。

I have been looking up on google to find out how to use linklabel to link to a Windows Form. All the tutorials that I've come across only link you to a URL or you local disk. Any help? I don't want to use buttons.

使用 LinkLabel 正如您将使用按钮一样,通过在click事件中执行代码。当用户单击标签时,以编程方式打开表单(或者如果它打开则将其带到前面)。您将无法设置表单的URL。

Use the LinkLabel as you would be using a button, by executing code in the click event. Open the form (or bring it to the front if it is alreay open) programmatically when the user clicks the label. You will not be able to set an URL to a form.

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    Form2 form2 = Application.OpenForms.OfType<Form2>().FirstOrDefault();
    if (form2 == null) {
        form2 = new Form2();
        form2.Show();
    } else {
        form2.BringToFront();
    }
}