Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opening a window form from another form programmatically

Tags:

I am making a Windows Forms application. I have a form. I want to open a new form at run time from the original form on a button click. And then close this new form (after 2,3 sec) programatically but from a thread other than gui main thread.

  1. Can anybody guide me how to do it ?
  2. Will the new form affect or hinder the things going on in the original main form ? (if yes than how to stop it ?)
like image 352
vow Avatar asked Feb 23 '13 14:02

vow


People also ask

How can I open one form from another form in VB net?

A form will be created with a default name of Form1. Add a second form by right-clicking the project and selecting Add, Add Windows Form from the menu that appears. Accept the default name of Form2 for the new form and click the Open button to finish the wizard.


2 Answers

To open from with button click please add the following code in the button event handler

var m = new Form1(); m.Show(); 

Here Form1 is the name of the form which you want to open.

Also to close the current form, you may use

this.close(); 
like image 153
Amrit Sharma Avatar answered Oct 10 '22 12:10

Amrit Sharma


I would do it like this:

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

and to close current form I would use

this.Hide(); instead of

this.close(); 

check out this Youtube channel link for easy start-up tutorials you might find it helpful if u are a beginner

like image 35
Tacit Avatar answered Oct 10 '22 11:10

Tacit