473,387 Members | 1,541 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,387 software developers and data experts.

.NET Design Advice - best way to navigate between WinForms?

I'm building an multiform Windows application that I anticipate will grow to
contain many forms. I would appreciate some "best practices" advice on the
cleanest way to call one form from another.

Up to now, I've called one form from another using the following syntax to
call one form from another. From my first form, the code looks like this:

frmMyForm2 frm = new frmMyForm2(this);

This is great, except that I have to specifiy a custom constructor in
frmMyForm2 to catch the passed parameter. The constructor would look like
this:

public frmMyForm2(frmMyForm1 frm)
{
InitializeComponent();
this.Show();
frm.Hide();
}

This isn't so bad if only one form is calling frmMyForm2. However, if this
form is central to the app there could easily be eight or ten forms calling
it. Rather than having to include eight or ten custom constructors in
frmMyForm2, is there some method of capturing the first form in the parameter
as a generic type so I only have to code one constructor?

Any advise or suggestions would be much appreciated. Thanks!

Andre

Nov 16 '05 #1
3 6821
Why not make the caller responsible for hiding itself?

frmMyForm2 frm = new frmMyForm2(this);
this.Hide();
frm.Show();

The only reason I can see to pass a reference to the other form is if there
are other more elaborate things you want to do to communicate back to the
original form later. Perhaps you want to do more than these Hide() and
Show() calls?

--Bob
"Andre Ranieri" <An**********@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
I'm building an multiform Windows application that I anticipate will grow
to
contain many forms. I would appreciate some "best practices" advice on
the
cleanest way to call one form from another.

Up to now, I've called one form from another using the following syntax to
call one form from another. From my first form, the code looks like this:

frmMyForm2 frm = new frmMyForm2(this);

This is great, except that I have to specifiy a custom constructor in
frmMyForm2 to catch the passed parameter. The constructor would look like
this:

public frmMyForm2(frmMyForm1 frm)
{
InitializeComponent();
this.Show();
frm.Hide();
}

This isn't so bad if only one form is calling frmMyForm2. However, if
this
form is central to the app there could easily be eight or ten forms
calling
it. Rather than having to include eight or ten custom constructors in
frmMyForm2, is there some method of capturing the first form in the
parameter
as a generic type so I only have to code one constructor?

Any advise or suggestions would be much appreciated. Thanks!

Andre

Nov 16 '05 #2
Maybe you think about some manager?
For example some singleton:

FormsMgr frmMgr = FormsMgr.Instance;
frmMgr.Add(Form someForm, string someStrongName);

frmMgr[string strongName].Show();
frmMgr[string strongName].Hide();

That should help you.

kuba florczyk
I'm building an multiform Windows application that I anticipate will grow to contain many forms. I would appreciate some "best practices" advice on the cleanest way to call one form from another.

Up to now, I've called one form from another using the following syntax to
call one form from another. From my first form, the code looks like this:

frmMyForm2 frm = new frmMyForm2(this);

This is great, except that I have to specifiy a custom constructor in
frmMyForm2 to catch the passed parameter. The constructor would look like
this:

public frmMyForm2(frmMyForm1 frm)
{
InitializeComponent();
this.Show();
frm.Hide();
}

This isn't so bad if only one form is calling frmMyForm2. However, if this form is central to the app there could easily be eight or ten forms calling it. Rather than having to include eight or ten custom constructors in
frmMyForm2, is there some method of capturing the first form in the parameter as a generic type so I only have to code one constructor?

Any advise or suggestions would be much appreciated. Thanks!

Andre

Nov 16 '05 #3
Why not use a tab control instead? You do not have to show the tabs. I
actually use a Frame / Box control and then just swap in and out the
contents per the user selection from a menu just like the way Outlook does
it.

JIM
"Andre Ranieri" <An**********@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
I'm building an multiform Windows application that I anticipate will grow
to
contain many forms. I would appreciate some "best practices" advice on
the
cleanest way to call one form from another.

Up to now, I've called one form from another using the following syntax to
call one form from another. From my first form, the code looks like this:

frmMyForm2 frm = new frmMyForm2(this);

This is great, except that I have to specifiy a custom constructor in
frmMyForm2 to catch the passed parameter. The constructor would look like
this:

public frmMyForm2(frmMyForm1 frm)
{
InitializeComponent();
this.Show();
frm.Hide();
}

This isn't so bad if only one form is calling frmMyForm2. However, if
this
form is central to the app there could easily be eight or ten forms
calling
it. Rather than having to include eight or ten custom constructors in
frmMyForm2, is there some method of capturing the first form in the
parameter
as a generic type so I only have to code one constructor?

Any advise or suggestions would be much appreciated. Thanks!

Andre

Nov 16 '05 #4

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

Similar topics

1
by: john | last post by:
Hello all. Thanks for reading and for any advice... Ok, I have a linux webserver with php/mysql/apache. Next, there are csv (comma separated values) log files on a user's WINDOWS machine (and...
5
by: Nick Malik | last post by:
reposting to a wider audience "Nick Malik" <nickmalik@hotmail.nospam.com> wrote in message news:WYONc.203854$XM6.119642@attbi_s53... > My turn to ask a question > > I am working on a plug-in...
3
by: Will Honea | last post by:
I just got stuck with cleaning up a mess of records for a group I belong to - circa 80k memebers - that are being kept on a variety of spreadsheets and Access databases by a bunch of different...
4
by: Nick Malik | last post by:
My turn to ask a question I am working on a plug-in for Sharepoint that will allow a developer to add workflow rules. One of the rules will inform the adapter that it should load a DLL that the...
3
by: bardo | last post by:
Hello all, I want to make an application withs centers around 1 windowform. This form I want to give the same appearance as the Outlook. I have a listbox on the left-handside then a splitter....
6
by: Dave Weber | last post by:
I'm in the process of writing an open-source plugin-enabled application. I know that you can define the API in several ways, and right now it is equipped as an Interface. The gist of the...
8
by: bob | last post by:
I am unsure how to approach a C# windows App. Essentially I want to do this. I want to write an app that reads from database_A performs some calculations updates the pretty dials on the screen...
4
by: Jerry | last post by:
Hello! I'm creating an application where users can enter their hours worked on certain projects and have them saved to a database. Right now there are about 60 different projects and that number...
0
by: Morton | last post by:
Hello, I'm in the process of making a class library for communicating with a PLC. I'm uncertain what would be the best design pattern to use. I've made some experimentations with the aggregate...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...
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...
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...

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.