Can I use LinkLabel on Visual Studios to link to a windows form?

与世无争的帅哥 提交于 2019-12-07 07:42:59

问题


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.


回答1:


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();
    }
}


来源:https://stackoverflow.com/questions/14465409/can-i-use-linklabel-on-visual-studios-to-link-to-a-windows-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!