Click here to Skip to main content
13,048,805 members (64,997 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a simple button in form1, I'm having a hard time making it that when you click on the button in form1 form1 will change into form2. The only thing I can do is make form2 open on a new form. I forgot how to do this and I need someone to help me jog my memory!

Posted 10-Jul-12 4:24am
Updated 10-Jul-12 4:26am
Wes Aday 10-Jul-12 10:27am
You mean: frm2.Show(); frm1.Hide(); ?
Sergey Alexandrovich Kryukov 10-Jul-12 15:45pm
What, you forgot how to make the impossible? Wow, please remember it as soon as you can, I want to know your trick. :-)
MR. AngelMendez 11-Jul-12 9:00am
yeah its an old hacker trick that was passed down to me but cant remember lol :)
Sergey Alexandrovich Kryukov 11-Jul-12 14:18pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can't actually change Form1 into Form2 - they are normally separate classes and can't be "mutated" from one into the other.
There are a couple of ways you can get that visual effect though.

The first is to make them the same size and shape, and set the new form StartPosition to Manual. You then set the Loctation property so that it matches the Form1. You can then Show the Form2, and Hide Form1 - do not try to use ShowDialog on Form2 unless you Hide Form1 first! If you do this, you must provide a way to return to Form1, or a different way to terminate the application - closing Form2 will not do that. One way is to handle the Form2 FormClosing event, and either Close Form1, or re-show it.

The other way is to put the whole of your form into a UserControl and display that on the Form surface. When you need to swap to "Form2" you just make the "Form1" UserControl Visible property false, and the "Form2" one true. Like magic, the form appears to change!

Personally, I tend to use the latter method.
MR. AngelMendez 10-Jul-12 11:23am
oooh user controls I forgot about those, never really could figure out how to display them on my form though. I'll need help with this.

OriginalGriff 10-Jul-12 12:03pm
Easy Peasy.
Create your controls and build your project (you haven't added them to your form yet).
You should find the controls appear in the toolbox.

If they don't, right click on the Toolbox, and select "Choose Items".
On the dialog that eventually appears, press the "Browse" button, and locate the DLL or EXE with the controls in.

You can now drag the controls onto your form.
MR. AngelMendez 11-Jul-12 9:07am
thank you so much OriginalGriff, I got it to work!!
OriginalGriff 11-Jul-12 9:29am
You're welcome!
Naerling 10-Jul-12 11:29am
UserControls definitely get my 5 :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 10 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100