PDA

View Full Version : c# form linking


DELOCH
07-28-2006, 06:27 PM
I have a really huge problem now... can you please help me?

I need to link forms eg: when a user clicks button1 the active form changes from form1 form to form2 form

I know how to make 2 forms in one project but I dont know how to link them between each other...

if this is not possible how am i able to remove objects from the form eg: off the stage...

Thanks... this would help me a lot... thanks for taking time to read and or reply :D

I will be deeply greatful for the one that helps me :D

paulq
07-28-2006, 07:00 PM
Looks like this link (http://www.c-sharpcorner.com/Code/2002/June/CommBetweenForms.asp) could be what you are looking for maybe?

DELOCH
07-28-2006, 07:20 PM
Thanks but the problem is not to send message between forms but...


I want to switch between form1 and form2

eg:

if the user clicks the button go to Form2 then the main form(form1) is not there but the form2 takes it's place

like a hyperlink in HTML

<a href="http://form2">something</a>

Thanks :D

Brandoe85
07-28-2006, 07:27 PM
Create a new instance of the second form, then show it.

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

Then hide or close the first form.
this.Hide();

etc...Good luck;

DELOCH
07-28-2006, 09:40 PM
this starts to make sence... but there is another problem...

I have 2 forms (Form1, Form2) and I have code:

Form2.Show();

and it doenst work

but when I do your way it works but it opens in a new window but I want it to turn Form1 to Form2 exactly in the same spot and only one frame open(Without opening in another window...)

Thanks, this helps though :D

oracleguy
07-28-2006, 10:42 PM
You can't do Form2.Show() since as you should already know, everything in C# is an object. You can't show an uninstantiated object like that. And show isn't a static method.

If you want form2 to be in the same spot, just alter it's startup location and size to match form1 before you call the show method.

DELOCH
07-28-2006, 11:30 PM
oh... so can I quickly close() the first form and show() the second form quickly then? thanks :D

Brandoe85
07-29-2006, 05:21 AM
Yes you can. You can also set the top and left properties of your second form to the top and left of your first form(like oracleguy (http://www.codingforums.com/member.php?u=515) was getting at), like:

Form2 frm2 = new Form2();
this.Hide();
frm2.Show();
frm2.Top = this.Top;
frm2.Left = this.Left;

oracleguy
07-29-2006, 08:05 PM
Well I was saying setting those properties before you show, so it draws it in the location you want right from the get go. But you pretty much got what I was saying. Though I'm not sure if the form has to be displayed first before those settings can be changed or not. Worth a try.

Brandoe85
07-29-2006, 09:59 PM
Yeah, Just tried it out, and I had to show the form before I set the properties. You'll see a little glitch when the form moves to the positions, but it's not so bad.

Melon00
08-08-2006, 07:15 PM
You can do it after you call the constructor for the second form. Also, it needs to be the same size as the other window for it to work.


Form2 frm2 = new Form2();
frm2.Region = this.Region;
frm2.Show();
this.Hide()

This should eliminate the glitch.

DELOCH
08-09-2006, 02:42 AM
Thanks how do I do this in C++

Because now I quit C++ because I couldn't link forms :\

Melon00
08-11-2006, 01:58 PM
The funny thing is, is that C++ is actually more powerful than C#. It is just that C++ is not developer friendly. Are you going to be using C++ .NET or MFC or ...?

DELOCH
08-15-2006, 02:51 PM
.NET, and I know it's not developer friendly that is why I rush to the most powerful languages all the time ^_^