Matthewj
Matthewj

Reputation: 2022

How to load form

In c# I'm working on a project and I try to make the program go to another form it does but its blank

Code:

   Form form2 = new Form();
   form2.Show();

Upvotes: 1

Views: 214

Answers (4)

CharithJ
CharithJ

Reputation: 47510

A new Form instance is just blank. You have to create an instance of your own customized Form (Form2?) and show.

May be like below.

// Create and display a modless Form2.
Form2 myForm = new Form2();
myForm.Show();

Look at here for more Form.Show() examples.

Upvotes: 1

Davide Piras
Davide Piras

Reputation: 44605

you are creating a new instance of the base class Form from which your application forms are deriving.

saying you have two forms in your application, Form1 and Form2, to show Form2 from Form1 do this:

var myForm2 = new Form2();
myForm2.Show();

Upvotes: 2

fardjad
fardjad

Reputation: 20394

You're making an instance of Form class which is the base class and should be blank.

Define your Form object like this instead:

var form2 = new Form2();
form2.Show();

Or

Form form2 = new Form2();
form2.Show();

Upvotes: 2

Sudantha
Sudantha

Reputation: 16194

You have to create a object of the form 2 like this

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

hope this helps

Upvotes: 2

Related Questions