473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

form within in form

Hi!

I have a question regarding Windows Forms...
Let's say I have two forms... MainForm and FormTwo... is it possible, when I
open
FormTwo from MainForm, to display FormTwo inside MainForm instead of in it's
own window?

Thanks,
Saso
Nov 15 '05 #1
6 9199

--------------------
From: "Saso Zagoranski" <sa*************@guest.arnes.si>
Newsgroups: microsoft.public.dotnet.languages.csharp
Subject: form within in form
Date: Wed, 3 Sep 2003 22:23:26 +0200
Organization: ARNES
Lines: 12
Message-ID: <bj**********@planja.arnes.si>
NNTP-Posting-Host: clj3-56.dial-up.arnes.si
X-Trace: planja.arnes.si 1062620606 15556 194.249.53.56 (3 Sep 2003 20:23:26 GMT)X-Complaints-To: ab***@arnes.si
NNTP-Posting-Date: Wed, 3 Sep 2003 20:23:26 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!newsfee
d01.sul.t-online.de!t-online.de!news.belwue.de!irazu.switch.ch!switch.ch !kan
ja.arnes.si!planja.arnes.si!not-for-mailXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:182048
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Hi!

I have a question regarding Windows Forms...
Let's say I have two forms... MainForm and FormTwo... is it possible, when Iopen
FormTwo from MainForm, to display FormTwo inside MainForm instead of in it'sown window?

Thanks,
Saso


Hi,
It sounds like you are taking about a multiple-document interface
application where MainForm would be the parent form and FormTwo would be
the child. Please refer to the link below for information and examples on
how to program this using Windows Forms. If this doesn't answer your
question please reply back to this thread.

http://msdn.microsoft.com/library/de...us/vbcon/html/
vbconmdiapplications.asp

Thanks,
Shruti Gupta
--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Nov 15 '05 #2
I'm thinking you must be talking about MDI (multiple document
interface). Here's a really dumb example:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace MdiExample {
public class Parent : Form {
public Parent() : base() {
this.ClientSize = new Size(400,300);
this.Text = "Mdi Example";
this.IsMdiContainer = true;
(new Child(this,"Who?")).Show();
(new Child(this,"What?")).Show();
(new Child(this,"When?")).Show();
}
}

public class Child : Form {
public Child(Form parent, string title) : base() {
this.ClientSize = new Size(100,75);
this.Text = title;
this.MdiParent = parent;
this.BackColor = Color.Red;
}

public static void Main(string[] args) {
Application.Run(new Parent());
}
}
}

Nov 15 '05 #3
Hi!

I tried the example you gave me... I have a Form (MainForm) on which I have
a button...
I edited the MainForm:
this.IsMdiContainer = true;

I edited FormTwo:
public FormTwo(Form parent, string text) : base()
{
this.MdiParent = parent;
}

When I press the button I execute:

FormTwo form2 = new FormTwo(this,"Some text");
form2.Show();

Nothing happens :(
What am I doing wrong?
"Kelly Norton" <pe******@kellegous.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I'm thinking you must be talking about MDI (multiple document
interface). Here's a really dumb example:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace MdiExample {
public class Parent : Form {
public Parent() : base() {
this.ClientSize = new Size(400,300);
this.Text = "Mdi Example";
this.IsMdiContainer = true;
(new Child(this,"Who?")).Show();
(new Child(this,"What?")).Show();
(new Child(this,"When?")).Show();
}
}

public class Child : Form {
public Child(Form parent, string title) : base() {
this.ClientSize = new Size(100,75);
this.Text = title;
this.MdiParent = parent;
this.BackColor = Color.Red;
}

public static void Main(string[] args) {
Application.Run(new Parent());
}
}
}

Nov 15 '05 #4


I tried to mimic the changes you described below. This example works
for me in both the 1.0 and 1.1 .NET framework. However, to use buttons
inside a MDI parent form would be (IMO) way outside of convention.
Typically the parent's UI is all menu and toolbar driven. You will
notice that the button I have on the MDI parent form just sort of floats
above all the children. Also, if you haven't already, you should make
sure that your Button's EventHandler is being fired by adding a quick
messagebox:

MessageBox.Show("Yessir, I am indeed working");
FormTwo form2 = new FormTwo(this,"Some text");
form2.Show();

That will at least tell you if your problem is in the spawning of child
forms or in the handling of the Button's Click delegate.

My slightly altered example is included below.
/kel
-----------------------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;

namespace MdiExample {
public class Parent : Form {
private Button button = null;

public Parent() : base() {
button = new Button();
button.Text = "Bam!";
button.Click += new EventHandler(this.OnUIEvent);
button.Location = new Point(0,0);
this.ClientSize = new Size(400,300);
this.Text = "Mdi Example";
this.IsMdiContainer = true;
this.Controls.Add(button);
}

public void OnUIEvent(object sender, EventArgs e) {
if (sender.Equals(button)) {
Form f = new Child(this,Guid.NewGuid().ToString());
f.Show();
}
}
}

public class Child : Form {
public Child(Form parent, string title) : base() {
this.ClientSize = new Size(100,75);
this.Text = title;
this.MdiParent = parent;
this.BackColor = Color.Red;
}

public static void Main(string[] args) {
Application.Run(new Parent());
}
}
}

Saso Zagoranski wrote:
Hi!

I tried the example you gave me... I have a Form (MainForm) on which I have
a button...
I edited the MainForm:
this.IsMdiContainer = true;

I edited FormTwo:
public FormTwo(Form parent, string text) : base()
{
this.MdiParent = parent;
}

When I press the button I execute:

FormTwo form2 = new FormTwo(this,"Some text");
form2.Show();

Nothing happens :(
What am I doing wrong?


Nov 15 '05 #5
Hi Kelly!

I found out what was wrong and you are right... The MDI parent form should
have just toolbars and main menus...
I removed the button from the MDI parent and it works great...

Just one more question...
I used to open FormTwo with ShowModal() and that way I could immediately
know, when FormTwo was closed...
How can MainForm now know when is FormTwo closed?

Thanks a lot...
Saso

"Kelly Norton" <pe******@kellegous.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...


I tried to mimic the changes you described below. This example works
for me in both the 1.0 and 1.1 .NET framework. However, to use buttons
inside a MDI parent form would be (IMO) way outside of convention.
Typically the parent's UI is all menu and toolbar driven. You will
notice that the button I have on the MDI parent form just sort of floats
above all the children. Also, if you haven't already, you should make
sure that your Button's EventHandler is being fired by adding a quick
messagebox:

MessageBox.Show("Yessir, I am indeed working");
FormTwo form2 = new FormTwo(this,"Some text");
form2.Show();

That will at least tell you if your problem is in the spawning of child
forms or in the handling of the Button's Click delegate.

My slightly altered example is included below.
/kel
-----------------------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;

namespace MdiExample {
public class Parent : Form {
private Button button = null;

public Parent() : base() {
button = new Button();
button.Text = "Bam!";
button.Click += new EventHandler(this.OnUIEvent);
button.Location = new Point(0,0);
this.ClientSize = new Size(400,300);
this.Text = "Mdi Example";
this.IsMdiContainer = true;
this.Controls.Add(button);
}

public void OnUIEvent(object sender, EventArgs e) {
if (sender.Equals(button)) {
Form f = new Child(this,Guid.NewGuid().ToString());
f.Show();
}
}
}

public class Child : Form {
public Child(Form parent, string title) : base() {
this.ClientSize = new Size(100,75);
this.Text = title;
this.MdiParent = parent;
this.BackColor = Color.Red;
}

public static void Main(string[] args) {
Application.Run(new Parent());
}
}
}

Saso Zagoranski wrote:
Hi!

I tried the example you gave me... I have a Form (MainForm) on which I have a button...
I edited the MainForm:
this.IsMdiContainer = true;

I edited FormTwo:
public FormTwo(Form parent, string text) : base()
{
this.MdiParent = parent;
}

When I press the button I execute:

FormTwo form2 = new FormTwo(this,"Some text");
form2.Show();

Nothing happens :(
What am I doing wrong?

Nov 15 '05 #6
Hi again! :)

I tried out your example and it works... but there is a problem if MainForm
and FormTwo are in different assemblies...

I call FormTwo from the main form, so I have a reference to the assembly
including FormTwo in the main form... but I can't have a reference from the
form Two assembly because of the circular dependency problem...

That means that I can't access the OnChildClosed() method from MainForm...

"Kelly Norton" <pe******@kellegous.com> wrote in message
news:OU****************@TK2MSFTNGP09.phx.gbl...
The easiest solution is to override the OnClosed event in the FormTwo
class and call back to the parent when a child closes. One important
thing to remember, though, is that the children will all close when the
parent closes (firing that event) so be sure to handle that properly.

just threw that into the example too.

/kel

----------------------------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;

namespace MdiExample {
public class Parent : Form {
private Button button = null;

public Parent() : base() {
button = new Button();
button.Text = "Bam!";
button.Click += new EventHandler(this.OnUIEvent);
button.Location = new Point(0,0);
this.ClientSize = new Size(400,300);
this.Text = "Mdi Example";
this.IsMdiContainer = true;
this.Controls.Add(button);
}

public void OnUIEvent(object sender, EventArgs e) {
if (sender.Equals(button)) {
Form f = new Child(this,Guid.NewGuid().ToString());
f.Show();
}
}

public void OnChildClosed(Child child) {
MessageBox.Show(String.Format("{0} is closing",child.Text));
}
}

public class Child : Form {
public Child(Form parent, string title) : base() {
this.ClientSize = new Size(100,75);
this.Text = title;
this.MdiParent = parent;
this.BackColor = Color.Red;
}

public static void Main(string[] args) {
Application.Run(new Parent());
}

protected override void OnClosed(EventArgs e) {
Parent p = (Parent)this.MdiParent;
p.OnChildClosed(this);
}
}
}

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
3
by: fh1996 | last post by:
Form.Owner and Form.Parent, what's the difference between them? Form.ShowDialog() and Form.Show(), when to use which? Form.Activated(), what does it mean when saying a Form is "activated"? ...
0
by: web1110 | last post by:
Hi again, I am referring an earlier question here trying to enlarge upon the concept I am pursuing.: Each object is a subassembly. They are all significantly different in detail and content...
7
by: Jon | last post by:
I am having a brain drought here. I used to code in VB until about 3 years ago. I guess it's not quite like a bicycle because man i feel dumb :) Here, quickly, is what i am trying to...
1
by: Lloyd Sheen | last post by:
I have the following situation: Need a user resizable user control. After much trying with user control I came across the idea of hosting the controls in a form marked as not TopLevel = false. ...
1
by: Geoff Jones | last post by:
Hi Can anybody give me some example code on creating a form within another form which is centered to the first form? Thanks in advance Geoff
1
by: HarpoleAndWhite | last post by:
I am trying to put together a point of sale system for a restaurant. On the servers menu, I would like to have command buttons that on their click event load a secondary form onto the servers menu...
2
by: menyki | last post by:
please can somebody help me debug this code. i wrote a code that will display a form within an interval but the is generating alot of errors. the code is as shown below. (am using visual basic.Net) ...
3
by: kate2272 | last post by:
Hi Guys I was wondering if it is possible to turn AllowEdits to false after data has been entered for individual fields within a form/sub-form. I've found that I can do this in the 'AfterUpDate'...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.