473,382 Members | 1,271 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,382 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 2618
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"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.