Y.Arsoy
Y.Arsoy

Reputation: 129

LinkLabel to open a new Form

I am making a Windows Forms application. I have a LinkLabel in Form1.

How can I open another form (Form2) when someone clicks on my LinkLabel?

Upvotes: 1

Views: 9071

Answers (3)

Blue Phoenix
Blue Phoenix

Reputation: 151

Use Linklable_LinkClicked event to open another form. Don't use Clicked event. Here is my example below:

 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        frmSecondForm secondForm = new frmSecondForm();
        secondForm.Show();
        this.Hide();
    }

Upvotes: 0

mohsen
mohsen

Reputation: 1806

In Visual studio select every control you want to use it's event, here select LinkLabel and from properties window click on Events tab , you will see list of events of selected control. Here you want to use click event .so you can double click on click event .visual studio will create below method for you

public void YourControlName_click ( object sender , EventArgs e )
{
    // Add code that you want execute when you click control
}

For display the form on screen you must use Show or ShowDialog method of Form class

Form1 f = new Form1();
f.ShowDialog();

So you must add above code to your method

public void YourControlName_click ( object sender , EventArgs e )
{
      Form1 f = new Form1();
      f.ShowDialog();
}

Upvotes: 1

Peter Bons
Peter Bons

Reputation: 29720

A LinkLabel is for opening an url. You probably want to create a "normal" Label and than handle to click event (double click the Label in the WinForms designer and it will generate one for you).

By the way, if you really need to use StackOverflow for this I suggest you watch some beginners video's first. Better try to understand thing first.

https://msdn.microsoft.com/en-us/library/dd492132.aspx

Upvotes: 1

Related Questions