Closing form.....

  • Thread starter Thread starter Mihailo
  • Start date Start date
M

Mihailo

I have two forms and that forms are connect with one button. When I click on
Button in the first form, the second form will be open. But both form are
open. I want when I click on the button to close first form and to open the
second but I don't know how, I know how to open second but to close the
first dont. If someone can help me I will be very
grateful.

Mihailo
 
Hello Mihailo,

In the first form's button click event, try [C#] this.Close(); or [VB] Me.Close()
 
Thanks it work with two forms. Now I want to open the third form and: I
click on the first form to open 3th form then it will open (logon form) with
password and username. I want when I type username and password and click on
OK to show 3th form but to close FIRST and LOGON form. I know, now, (thanks
to you) how to close logon form but it always stay open 1st form. How can I
do that? I experiment a little but it didnt work.
Thanks a lot for preview help!
 
Hello Mihailo,

You can pass a variable containing your first form to your third form and
then call the Close method on that variable.
 
Matt Berther said:
Hello Mihailo,

You can pass a variable containing your first form to your third form and
then call the Close method on that variable.


I have that idea too. I wrote in the 3th form: dim form1 as new frmForm1
and in event load for the 3th form I wrote form1.close()
but when I start the project I cant do that. Debugger don't send the error
but it didn't start.
Anyway thanks for an idea.

Mihailo
 
Hello Mihailo,

You'll need to have a method on the 3rd form that takes a reference to the
first form.

// Form3
private Form opener;
public void SetOpener(Form form)
{
this.opener = form;
}

then use opener.Close() in whatever method you feel is appropriate

// Form1
Form3 form = new Form3();
form.SetOpener(this);
form.Show();
 
Matt Berther said:
Hello Mihailo,

You'll need to have a method on the 3rd form that takes a reference to the
first form.

// Form3
private Form opener;
public void SetOpener(Form form)
{
this.opener = form;
}

then use opener.Close() in whatever method you feel is appropriate

// Form1
Form3 form = new Form3();
form.SetOpener(this);
form.Show();


I am beginner in this and I don't understand this very well but. I try and I
hope I will do this. Thanks a lot I will give the best to solve this with
your help.

Mihailo
 
Back
Top