Link to home
Start Free TrialLog in
Avatar of awilderbeast
awilderbeastFlag for United Kingdom of Great Britain and Northern Ireland

asked on

C# windows form, open a form from another form in same window

hi all, just creating my first windows app have the below code

only problem  is that it opens the form in a new window, i would like to have the form open in the same window

that possible?

Thanks
void _CompaniesFrm(object sender, ExecuteEventArgs e)
        {
            App.Companies.FrmCompanies obj = new App.Companies.FrmCompanies();
            obj.Show();
        }

Open in new window

Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

No. Forms in a Windows application are seperate entities, they don't all draw within the same window as you would with a web page.

You can house the forms in an MDI window if you wanted to, but each seperate window would still display separately.
Avatar of awilderbeast

ASKER


so an MDI window would give the apperance of them looking like their in one window though?

child forms go in the same window though dont they?

Thanks
The MDI window acts as a parent for the child windows. So each child will appear within the bounds of the MDI parent form, but they will still be separate windows.

This is worth a read to help clarify things:

    http://www.c-sharpcorner.com/UploadFile/ggaganesh/DevelopingMDIAppplicationsinCSharp11272005225843PM/DevelopingMDIAppplicationsinCSharp.aspx
ASKER CERTIFIED SOLUTION
Avatar of systan
systan
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi awilderbeast;

Are you looking to do something like this.

Fernando
ScreenShot002.png
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that example is exactly what i needed, got it sorted now

is there a way i can hide/remove the title bar and menu so it looks like its the same page?
also is there a way i can change main forms

im guessing close one open another, but is there a way of that happening without screen flicker?

Thanks
i ahve the below but its being cheeky and showing up still

in form load i did the below both ways round (as i read it makes a difference) and it comes back with it almost but not quite each way
this.FormBorderStyle = FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;

Open in new window

almost.PNG
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi awilderbeast;

To remove the title bar us the property FormBorderStyle  as shown below

            NewForm nf = new NewForm( );
            nf.TopLevel = false;
            // Remove Border / Title bar from the form
            nf.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            panel1.Controls.Add( nf );
            nf.Show( );

Open in new window


Fernando
i dont like the animation between forms, i would like to click and it just be there, without looking like one is openeing and closing

can an application context do this?

Thanks

also thanks to fernado for the hiding border :)
If the forms aren't too complex, another option is to use one form with 2 panels on it.  Put all the controls for the first form inside panel1, and all the controls for the second form inside panel2, put the two panels on top of each other, then change their visibility.

Alternatively use Show()/Hide() instead of Open()/Close()
ive tried show hide and open close, they both have animation on them instead of just a static transfer

the problem is im using windows Ribbon for WinForms, and i need a different menu ribbon depending on which section, but im not keen on the crappy animation that happens when you open close, show/hide a form :S
>>that example is exactly what i needed, got it sorted now
Using the Panel? The one that I send to you? Whos example?
thanks
Hi, first you create one mdi form then when you click on the button of that form at that time write this code

childform objch = new childform();
objch.MdiParent = this.MdiParent;
objch.show();

it is working properly.