473,813 Members | 3,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9218

--------------------
From: "Saso Zagoranski" <sa************ *@guest.arnes.s i>
Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
Subject: form within in form
Date: Wed, 3 Sep 2003 22:23:26 +0200
Organization : ARNES
Lines: 12
Message-ID: <bj**********@p lanja.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.ph x.gbl!TK2MSFTNG P08.phx.gbl!new sfeed00.sul.t-online.de!newsf ee
d01.sul.t-online.de!t-online.de!news. belwue.de!irazu .switch.ch!swit ch.ch!kan
ja.arnes.si!pla nja.arnes.si!no t-for-mailXref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1820 48
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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/
vbconmdiapplica tions.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.IsMdiConta iner = true;
(new Child(this,"Who ?")).Show();
(new Child(this,"Wha t?")).Show();
(new Child(this,"Whe n?")).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.IsMdiConta iner = 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,"S ome text");
form2.Show();

Nothing happens :(
What am I doing wrong?
"Kelly Norton" <pe******@kelle gous.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.IsMdiConta iner = true;
(new Child(this,"Who ?")).Show();
(new Child(this,"Wha t?")).Show();
(new Child(this,"Whe n?")).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,"S ome 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(th is.OnUIEvent);
button.Location = new Point(0,0);
this.ClientSize = new Size(400,300);
this.Text = "Mdi Example";
this.IsMdiConta iner = true;
this.Controls.A dd(button);
}

public void OnUIEvent(objec t sender, EventArgs e) {
if (sender.Equals( button)) {
Form f = new Child(this,Guid .NewGuid().ToSt ring());
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.IsMdiConta iner = 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,"S ome 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******@kelle gous.com> wrote in message
news:%2******** ********@tk2msf tngp13.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,"S ome 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(th is.OnUIEvent);
button.Location = new Point(0,0);
this.ClientSize = new Size(400,300);
this.Text = "Mdi Example";
this.IsMdiConta iner = true;
this.Controls.A dd(button);
}

public void OnUIEvent(objec t sender, EventArgs e) {
if (sender.Equals( button)) {
Form f = new Child(this,Guid .NewGuid().ToSt ring());
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.IsMdiConta iner = 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,"S ome 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******@kelle gous.com> wrote in message
news:OU******** ********@TK2MSF TNGP09.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(th is.OnUIEvent);
button.Location = new Point(0,0);
this.ClientSize = new Size(400,300);
this.Text = "Mdi Example";
this.IsMdiConta iner = true;
this.Controls.A dd(button);
}

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

public void OnChildClosed(C hild 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(EventA rgs e) {
Parent p = (Parent)this.Md iParent;
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
74148
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 Form1.Visible = False Load (Form1)
3
7538
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"? Thanks!
0
1251
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 but are all derived from an abstract subassembly class. An assembly is defined as a tree of subassemblies. There are multiple levels of subassemblies that can be assembled in many different
7
1736
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 accomplish... One way or another i need a form to appear inside another form when clicking a command button. Example... I have a Form - we'll call it Form1 - we'll say it has a
1
1571
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. This work fine for most cases, allowing the user to resize the form (and controls within the form. The forms them selves are create dynamically when the user drags a node from a listview to a panel (contained in a Usercontrol which is hosted by...
1
1203
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
3474
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 (in a subform or display box, etc.). For example, once the lunch button is clicked, the lunch form should load into the servers menu (via a subform, etc.) containing more command buttons that are linked to database food items. What kind of...
2
1383
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) Dim myTimer As New System.Timers.Timer myTimer.Enabled = True myTimer.Interval = 70 Me.Close() mainForm.Show()
3
3207
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' by assigning Me.AllowEdits = False .... BUT this then doesn't allow me to update data in other fields within that form/sub-form after it has been saved ... it seems to assign this property all the other fields within the form/sub-form ... Any...
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10139
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7678
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4357
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.