473,406 Members | 2,769 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,406 software developers and data experts.

Are there problems with Nesting Forms

I've always been a bit annoyed by the over 200 methods and properties that
are inherited from Form, so I came up with a technique to get around this. I
create the Form in the designer, and then I wrap the Form class in an outer
class that acts as my dialog. This lets me keep the interface limited to the
the properties and methods that pertain directly to my dialog. I'm about to
implement this, but I'm afraid of any potential negative side effects. One
thing that worries me, is will the nested form plug into the message loop
correctly. So far the code runs ok, but I'm afraid of an unsuspecting side
effect nailing me at a critical time, i.e. during a demo. Here's an example
of what I'm doing.

public class ActionDialog:IDisposable
{
private ActionForm _form = new ActionForm();

//ActionDialog Definition....

public DialogResult ShowDialog(IWin32Window owner)
{
//Setup Form...
return _form.ShowDialog(owner);
}

public void Dispose()
{
_form.Dispose();
}
private class ActionForm : Form
{
//ActionForm definition....
}
}
Nov 17 '05 #1
2 2620
This will work fine. The only problem with this is that you won't be
able to use your form where parameters of type Form are expected. If you
can live with this, then you are fine.

However, I honestly wouldn't do this though, as you are going to find
(as the amount of reuse becomes greater) that you will need to expose more
and more from the underlying form, at which point, you will just end up
deriving from Form anyways.

It's excessive code which isn't going to improve the maintainability,
performance, or usability of your code.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- ca*******@caspershouse.com

"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:5E**********************************@microsof t.com...
I've always been a bit annoyed by the over 200 methods and properties that
are inherited from Form, so I came up with a technique to get around this.
I
create the Form in the designer, and then I wrap the Form class in an
outer
class that acts as my dialog. This lets me keep the interface limited to
the
the properties and methods that pertain directly to my dialog. I'm about
to
implement this, but I'm afraid of any potential negative side effects.
One
thing that worries me, is will the nested form plug into the message loop
correctly. So far the code runs ok, but I'm afraid of an unsuspecting
side
effect nailing me at a critical time, i.e. during a demo. Here's an
example
of what I'm doing.

public class ActionDialog:IDisposable
{
private ActionForm _form = new ActionForm();

//ActionDialog Definition....

public DialogResult ShowDialog(IWin32Window owner)
{
//Setup Form...
return _form.ShowDialog(owner);
}

public void Dispose()
{
_form.Dispose();
}
private class ActionForm : Form
{
//ActionForm definition....
}
}

Nov 17 '05 #2


"Nicholas Paldino [.NET/C# MVP]" wrote:
This will work fine. The only problem with this is that you won't be
able to use your form where parameters of type Form are expected. If you
can live with this, then you are fine.

However, I honestly wouldn't do this though, as you are going to find
(as the amount of reuse becomes greater) that you will need to expose more
and more from the underlying form, at which point, you will just end up
deriving from Form anyways.

It's excessive code which isn't going to improve the maintainability,
performance, or usability of your code.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- ca*******@caspershouse.com

"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:5E**********************************@microsof t.com...
I've always been a bit annoyed by the over 200 methods and properties that
are inherited from Form, so I came up with a technique to get around this.
I
create the Form in the designer, and then I wrap the Form class in an
outer
class that acts as my dialog. This lets me keep the interface limited to
the
the properties and methods that pertain directly to my dialog. I'm about
to
implement this, but I'm afraid of any potential negative side effects.
One
thing that worries me, is will the nested form plug into the message loop
correctly. So far the code runs ok, but I'm afraid of an unsuspecting
side
effect nailing me at a critical time, i.e. during a demo. Here's an
example
of what I'm doing.

public class ActionDialog:IDisposable
{
private ActionForm _form = new ActionForm();

//ActionDialog Definition....

public DialogResult ShowDialog(IWin32Window owner)
{
//Setup Form...
return _form.ShowDialog(owner);
}

public void Dispose()
{
_form.Dispose();
}
private class ActionForm : Form
{
//ActionForm definition....
}
}

Thanks for the advice. I see your point, and I will consequently take your advice.

Nov 17 '05 #3

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

Similar topics

0
by: Wolfgang Schwanke | last post by:
Dear usenet, I'm having the following small problem. I've been ask to add some Quicktime panoramas to a website. The author of the panoramas has made two versions of each: One in MOV format,...
2
by: Tamlin | last post by:
Hi all, I'm getting a bug with the datagrid object. I've created one from scratch, bound it to a dataview with 2 int32 columns and formatted the output as currency. I've found that when you...
1
by: Max Harvey | last post by:
Hi, I made up a nice little form which had its own sub form in it. I made a litle VB code so that when I pressed a button it would move form the form (frmConference) to the subform...
42
by: Mantorok Redgormor | last post by:
I have a question for the sages here. the comp.lang.c faq says: 20.20: Why don't C comments nest? Are they legal inside quoted strings? A: C comments don't nest because PL/I's comments...
8
by: Hardrock | last post by:
I encountered some difficulty in implementing dynamic loop nesting. I.e. the number of nesting in a for(...) loop is determined at run time. For example void f(int n) { For(i=0; i<=K; i++)...
4
by: kl.vanw | last post by:
I would like to count the nesting level in template classes. How can I make the following work? #include <assert.h> template <class T> class A { public: A() { // what goes here?
0
by: colleen1980 | last post by:
There is a report which i am trying to debug. This is the main query which runs in the report: qry_TopTenErrorReport_Crosstab If any idea/help whats is going on in the query i would be very...
6
by: stephen.cunliffe | last post by:
Hi, I'm looking for opinion/facts/arguments on the correct nesting of UL, OL, & LI elements. For example, this is what I want (unordered list): * Item 1 * Item 2 * Item 3
2
by: John Kotuby | last post by:
Hi all, I have a page that displays the contents of a business document in HTML that uses multiple select queries to provide the relevent data. There is a call to the parent table and then...
17
by: henry | last post by:
Folks Here's a skeleton, generic HTML page, call it "index.php". You'll see a bit of php code in the middle: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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
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.