GUI Forms - should be simple 
Author Message
 GUI Forms - should be simple

This should be something simple I'm just missing, but I
can't figure out how to display new forms or panels within
my main application.  I have a main application form which
is started in the Main static method, and this form has my
menus at the top (like File -> Save As..., Save, etc.).  
What I can't figure out is how to get a new form to
display in the main display region of the application when
a menu or button is clicked, but I want to keep my menus.

In Java the main form-like object is the JFrame and you
use the JFrame.getContentPane() method to get the display
region and add panels and things to it without messing
with the menubar.  Is there a similar technique in C# to
do this?  I've tried using:
Form2 f2 = new Form2();
f2.Show();
but this just displays a whole new window, which I don't
want.  Should I be adding Panel objects to my main form
instead?  I also want to be able to use the Visual
Studio .NET IDE to layout the forms (It's so much easier
that Java!!)  But can i use it to layout Panel objects or
only Forms?  Thanks for any help!
Zack



Sun, 05 Sep 2004 01:53:38 GMT  
 GUI Forms - should be simple
You are close:

Form2 f2 = new Form2();
f2.MdiParent = this;
f2.Show();

This is assuming that this is the form that you want the new form to load
in.  The form that you are loading the new form needs to have the property
IsMdiContainer set to true.

Scott


Quote:
> This should be something simple I'm just missing, but I
> can't figure out how to display new forms or panels within
> my main application.  I have a main application form which
> is started in the Main static method, and this form has my
> menus at the top (like File -> Save As..., Save, etc.).
> What I can't figure out is how to get a new form to
> display in the main display region of the application when
> a menu or button is clicked, but I want to keep my menus.

> In Java the main form-like object is the JFrame and you
> use the JFrame.getContentPane() method to get the display
> region and add panels and things to it without messing
> with the menubar.  Is there a similar technique in C# to
> do this?  I've tried using:
> Form2 f2 = new Form2();
> f2.Show();
> but this just displays a whole new window, which I don't
> want.  Should I be adding Panel objects to my main form
> instead?  I also want to be able to use the Visual
> Studio .NET IDE to layout the forms (It's so much easier
> that Java!!)  But can i use it to layout Panel objects or
> only Forms?  Thanks for any help!
> Zack



Sun, 05 Sep 2004 02:37:49 GMT  
 GUI Forms - should be simple
Don't know Java but I am assuming you want to create a multi document
interface and want to specify the layout of child windows with a menuitem.
Here is a quick sample in C#

//  Compile with csc filename.cs
using System;
using System.Windows.Forms;

class Test : Form{
      StatusBar sb;
      public Test()
      {
           IsMdiContainer = true;
           MainMenu mi = new MainMenu();
           this.Menu = mi;
           Text = "I am the parent window";  
           mi.MenuItems.Add("&File",new EventHandler(file_click));
           mi.MenuItems.Add("&Layout -Tile Horizontally",new
EventHandler(layout_click));
           sb = new StatusBar();
           this.Controls.Add(sb);
      }

      public static void Main()
      {
          Application.Run(new Test());
      }

     public void file_click(Object o, EventArgs args)
     {
       Form  cp = new Form();
       cp.MdiParent = this;
       cp.Show();
       cp.Text = "I am the child window";
       sb.Text = "Here is the child window";
     }

    public void layout_click(Object o, EventArgs args)
   {
       this.LayoutMdi(MdiLayout.TileHorizontal);
       sb.Text = "MdiLayout.TileHorizontal";
   }

Quote:
}

//To run click File menu 2-3 times and then click on Layout Menu.

Hope this will help. For more information see MSDN docs and
http://samples.gotdotnet.com/quickstart/winforms/

Thanks,
Indira Dhingra
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get to know .NET?  http://www.gotdotnet.com
Security concern?  http://www.microsoft.com/security
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--------------------
| Content-Class: urn:content-classes:message


| Subject: GUI Forms - should be simple
| Date: Tue, 19 Mar 2002 09:53:38 -0800
| Lines: 23

| MIME-Version: 1.0
| Content-Type: text/plain;
|       charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
| Thread-Index: AcHPbv+SsPV5DeYnTQGpbz7f/YVcEQ==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: TKMSFTNGXA01 10.201.232.160
| Path: cpmsftngxa07!tkmsftngxs02!cpmsftngxa08
| Xref: cpmsftngxa07 microsoft.public.dotnet.languages.csharp:47159
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| This should be something simple I'm just missing, but I
| can't figure out how to display new forms or panels within
| my main application.  I have a main application form which
| is started in the Main static method, and this form has my
| menus at the top (like File -> Save As..., Save, etc.).  
| What I can't figure out is how to get a new form to
| display in the main display region of the application when
| a menu or button is clicked, but I want to keep my menus.
|
| In Java the main form-like object is the JFrame and you
| use the JFrame.getContentPane() method to get the display
| region and add panels and things to it without messing
| with the menubar.  Is there a similar technique in C# to
| do this?  I've tried using:
| Form2 f2 = new Form2();
| f2.Show();
| but this just displays a whole new window, which I don't
| want.  Should I be adding Panel objects to my main form
| instead?  I also want to be able to use the Visual
| Studio .NET IDE to layout the forms (It's so much easier
| that Java!!)  But can i use it to layout Panel objects or
| only Forms?  Thanks for any help!
| Zack
|



Sun, 05 Sep 2004 03:07:45 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Program to convert simple html forms to aspx form controls

2. Am i being studpid, Forms question

3. Does VC.Net Support a Forms-Based GUI Design like VB and C#

4. How to create a forms based gui

5. custom GUI/form

6. GUI Forms

7. form location - am I being thick?

8. I am confused in Form.Close()

9. GUI for simple operating system?

10. simple console app, how to add gui, good books for it mfc vs win32

11. Help with simple GUI

12. Simple GUI IO

 

 
Powered by phpBB® Forum Software