Bogdan0804
Bogdan0804

Reputation: 27

How do I make another form open when I click a button?

I've made another form in my project, and i wanted to know how to open inside of another form? Can you please help me!

Here is the code that I've got so far:

private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
{
     ???
}

Help me, I'm a beginner In c#

Upvotes: 0

Views: 431

Answers (1)

Simon
Simon

Reputation: 1312

There are two options:

  1. Designing a Form inside the Visual Studio Designer and open a new instance of this inside your code
  2. Create a new form and add elements (Labels, ...) inside your code

1:

Form2 frm2 = new Form2();
frm2.Open();

2:

Form aForm = new Form();
aForm.Text = "Title";

//Add Elements
Label l1 = new Label();
l1.Text = "Some Text";
l1.Location = new Point(10, 10);

aForm.Children.Add(l1);

//Show Form
aForm.Show();

Upvotes: 1

Related Questions