Switching to another form

  • Thread starter Thread starter John. S.
  • Start date Start date
J

John. S.

Hi,
I've created two forms at design time: Form1 and Form2.
Form1 is the main form.
I'd like to switch to Form2 if a button is clicked on Form1.
What is the proper way to accomplish that?
I know the Show() and ShowDialog() functions but don't
know how to use them.
Do I need to add some - #include "Form2.h" - to somewhere?

Thanks...
 
John. S. said:
Hi,
I've created two forms at design time: Form1 and Form2.
Form1 is the main form.
I'd like to switch to Form2 if a button is clicked on Form1.
What is the proper way to accomplish that?
I know the Show() and ShowDialog() functions but don't
know how to use them.
Do I need to add some - #include "Form2.h" - to somewhere?

Thanks...

Ask you boss to send you for a six month programming traning.

MH
 
Ask you boss to send you for a six month programming traning.

That wasn't very helpful.

John,

you need to create instance of the form2 first than call .Show() or
ShowDial0g() on that instance, like that:

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

if you need to make form1 owner of the form2, you can use ShowDialog method
and pass in Form1 reference.

Form2 form = new Form2();
form2.Show(this);

I hope it helps
 
WebMatrix said:
That wasn't very helpful.

Hmmm... I would argue on this one with you but I need your help, so I
won't.

Can you fix my funny CheckBox? See my post "Funny CheckBox".

MH
 
OK, forget.

LeftToRight should be false.
CheckAlign should be MiddleRight.
Next just to fiddle with the size.
 
Marius Horak said:
Hmmm... I would argue on this one with you but I need your help, so I
won't.

Can you fix my funny CheckBox? See my post "Funny CheckBox".

Ask you boss to send you for a six month programming traning.
How is that? Helpful?
 
WebMatrix said:
Ask you boss to send you for a six month programming traning.
How is that? Helpful?

Sorry, you are too late with your advice.
In this case scratching head for a minute or two and swearing at the PC
(it's what a real programmer does) solved the problem.

MH
 
Thanks for the quick reply.

I think it should be:
Form2 form = new Form2();
form.Show();

(I used (as C++)

Form2 *form = new Form2();
form->Show();

and it worked)

The problem is: I'm used to Borland C++ Builder (altough my C++ is not
perfect)
and Form2 refers to an instance, not a class in Borland C++ Builder. In BCB
,
displaying Form2 is as easy as calling Form2->Show();

But here Form2 refers to a class.
Anyway, I should have thought that somehow I have to create an instance of a
class.

Thanks again.
 
Ask you boss to send you for a six month programming traning.

Maybe you should ask your parents to send you for a six years training on
"How to speak in a newsgroup".
 
I'm having a similar problem. I created a second form and it's withing the
same namespace. However, when I try:

Form2 *form = new Form2();
form->Show();

I get Form2 is an undeclared identifier. Any ideas?

Thanks...
 
Back
Top