By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,694 Members | 2,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,694 IT Pros & Developers. It's quick & easy.

Windows Forms - Opening forms within forms

P: n/a
In my application I have a form (Customer) that I want to be able to open
multiple copies at once. Within this form I have other forms that can be
opened. Example: ZipCode. When the user enters a zipcode that is unknown
this form will open. I don't want users to modify any of this customers
data until they close the zipcode form. Normally this can accomplished
using a modal form, however this prevents me from opening a new copy of the
Customer form while the zipcode form is open.

How do you normally go about handling this scenario ?
--
Thanks,
Dan Tallent

Aug 26 '08 #1
Share this Question
Share on Google+
21 Replies


P: n/a
On Aug 26, 8:58*am, "Dan Tallent" <s...@microsoft.comwrote:
In my application I have a form (Customer) that I want to be able to open
multiple copies at once. *Within this form I have other forms that can be
opened. Example: ZipCode. * *When the user enters a zipcode that is unknown
this form will open. * I don't want users to modify any of this customers
data until they close the zipcode form. * Normally this can accomplished
using a modal form, however this prevents me from opening a new copy of the
Customer form while the zipcode form is open.

How do you normally go about handling this scenario ?

--
Thanks,
Dan Tallent
I guess use a modeless form. Or, use a class in lieu of using
forms.

RL
Aug 26 '08 #2

P: n/a
I knew it must be a modeless form, otherwise the entire application is stuck
waiting.

As far as "use a class"...what do you mean? All objects are classes of
some kind.

This code
Child1 C = new Child1();C.StartPosition = FormStartPosition.CenterParent;

C.TopLevel = false;

C.Parent = this;

C.Top = (this.Height - C.Height) / 2;

C.Left = (this.Width - C.Width) / 2;

C.Show();

C.BringToFront();



"raylopez99" <ra********@yahoo.comwrote in message
news:5b**********************************@v26g2000 prm.googlegroups.com...
On Aug 26, 8:58 am, "Dan Tallent" <s...@microsoft.comwrote:
In my application I have a form (Customer) that I want to be able to open
multiple copies at once. Within this form I have other forms that can be
opened. Example: ZipCode. When the user enters a zipcode that is unknown
this form will open. I don't want users to modify any of this customers
data until they close the zipcode form. Normally this can accomplished
using a modal form, however this prevents me from opening a new copy of
the
Customer form while the zipcode form is open.

How do you normally go about handling this scenario ?

--
Thanks,
Dan Tallent
I guess use a modeless form. Or, use a class in lieu of using
forms.

RL
Aug 26 '08 #3

P: n/a
Unfortunately this code still allows the user to modify the part form. If
I set Enabled = false on the parent form it also kills the child form.

Any ideas?

Thanks
Dan


"Dan Tallent" <sp**@microsoft.comwrote in message
news:OU**************@TK2MSFTNGP02.phx.gbl...
>I knew it must be a modeless form, otherwise the entire application is
stuck waiting.

As far as "use a class"...what do you mean? All objects are classes of
some kind.

This code
Child1 C = new Child1();C.StartPosition = FormStartPosition.CenterParent;

C.TopLevel = false;

C.Parent = this;

C.Top = (this.Height - C.Height) / 2;

C.Left = (this.Width - C.Width) / 2;

C.Show();

C.BringToFront();



"raylopez99" <ra********@yahoo.comwrote in message
news:5b**********************************@v26g2000 prm.googlegroups.com...
On Aug 26, 8:58 am, "Dan Tallent" <s...@microsoft.comwrote:
>In my application I have a form (Customer) that I want to be able to open
multiple copies at once. Within this form I have other forms that can be
opened. Example: ZipCode. When the user enters a zipcode that is unknown
this form will open. I don't want users to modify any of this customers
data until they close the zipcode form. Normally this can accomplished
using a modal form, however this prevents me from opening a new copy of
the
Customer form while the zipcode form is open.

How do you normally go about handling this scenario ?

--
Thanks,
Dan Tallent

I guess use a modeless form. Or, use a class in lieu of using
forms.

RL

Aug 26 '08 #4

P: n/a
I'm sure there are other options, but you could have the Customer form have a
private instance of a Zipcode form. When the Customer form needs the Zipcode
form, it makes it visible. Change the enabled property of the Customer form
to false when the Zipcode form is shown. Add a handler for when the Zipcode
form is made invisible (VisibilityChanged), at which point the Customer form
becomes enabled.

"Dan Tallent" wrote:
In my application I have a form (Customer) that I want to be able to open
multiple copies at once. Within this form I have other forms that can be
opened. Example: ZipCode. When the user enters a zipcode that is unknown
this form will open. I don't want users to modify any of this customers
data until they close the zipcode form. Normally this can accomplished
using a modal form, however this prevents me from opening a new copy of the
Customer form while the zipcode form is open.

How do you normally go about handling this scenario ?
--
Thanks,
Dan Tallent

Aug 26 '08 #5

P: n/a
Thanks for your reply.

I thought of something similar that when the ZipCode form was opened it
disabled the Customer form. The customer form subscribed to the FormClosed
event of the Zipcode form. This seems to work but it does have some
problems.
1 The Customer form can't be minimized or moved.
2 The Zipcode form can be moved outside the range of the Customer (parent)
form.
3 When you open a couple of customer forms it difficult (from a user point
of view) to tell which Customer screen the ZipCode is associated with.

If I could find a way to prevent the user from moving the ZipCode form
outside the boundries of the Customer form this would work perfectly. I
tried making the Customer form the parent, but when I disable the Customer
form the Zipcode form is disabled as well.

Thanks
dan

"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:14**********************************@microsof t.com...
I'm sure there are other options, but you could have the Customer form
have a
private instance of a Zipcode form. When the Customer form needs the
Zipcode
form, it makes it visible. Change the enabled property of the Customer
form
to false when the Zipcode form is shown. Add a handler for when the
Zipcode
form is made invisible (VisibilityChanged), at which point the Customer
form
becomes enabled.

"Dan Tallent" wrote:
>In my application I have a form (Customer) that I want to be able to open
multiple copies at once. Within this form I have other forms that can be
opened. Example: ZipCode. When the user enters a zipcode that is
unknown
this form will open. I don't want users to modify any of this customers
data until they close the zipcode form. Normally this can accomplished
using a modal form, however this prevents me from opening a new copy of
the
Customer form while the zipcode form is open.

How do you normally go about handling this scenario ?
--
Thanks,
Dan Tallent


Aug 26 '08 #6

P: n/a
Why don't you try redesigning abit. Make the "ZIP form" a user
control. Then on your Customer form center a hidden by default panel.
Then when your logic requires it, Show that panel while disabling the
rest of the controls behind it. The Customer form can still be
minimized, the ZIP *panel* is really part of form's layout, so no
confusion which ZIP panel belongs to which Customer form...
Will that work?
Aug 26 '08 #7

P: n/a
I looked into this method as well. I found I could use a form for the
ZipCode just as easily. The zipcode form can have its Parent set to the
Customer form which elimates the confusion. The form stays within the
boundry of the Customer form, and the Customer (parent) form can still be
minimized. The trick would be that I would need to write code to disable
all of the controls on the form manually. I have older apps that I've done
this with, but I was thinking I was doing this the hard way.

I suppose I could write a routine to loop though all the controls on the
form to disable/enable them. The problem there would be during the enable
knowing which controls should remain disabled.

Thanks for help. All suggestions are appreciated.
Dan


"G.S." <gs******@gmail.comwrote in message
news:22**********************************@c65g2000 hsa.googlegroups.com...
Why don't you try redesigning abit. Make the "ZIP form" a user
control. Then on your Customer form center a hidden by default panel.
Then when your logic requires it, Show that panel while disabling the
rest of the controls behind it. The Customer form can still be
minimized, the ZIP *panel* is really part of form's layout, so no
confusion which ZIP panel belongs to which Customer form...
Will that work?

Aug 26 '08 #8

P: n/a
On Aug 26, 10:08*am, "Dan Tallent" <s...@microsoft.comwrote:
This code
Child1 C = new Child1();C.StartPosition = FormStartPosition.CenterParent;

C.TopLevel = false;

C.Parent = this;
Well there's your problem right there Dan. You are creating a
potential circular reference with the 'this' pointer on the RHS. By
the logic of your program (if I'm reading it correctly), the child
form has a member variable Parent, and you are essentially saying the
parent is the child. For the root node (first parent to every form,
or Form 1) I guess this is OK, but for every other subform it's not.

Did you program the lunar module that landed (or didn't) on Mars by
any chance?

RL
Aug 26 '08 #9

P: n/a
Have you tried making Customer be an MDI Container? It won't work if
Customer is contained within an MDI Container, but it sounds like what you
are after.

"Dan Tallent" <sp**@microsoft.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I looked into this method as well. I found I could use a form for the
ZipCode just as easily. The zipcode form can have its Parent set to the
Customer form which elimates the confusion. The form stays within the
boundry of the Customer form, and the Customer (parent) form can still be
minimized. The trick would be that I would need to write code to disable
all of the controls on the form manually. I have older apps that I've done
this with, but I was thinking I was doing this the hard way.

I suppose I could write a routine to loop though all the controls on the
form to disable/enable them. The problem there would be during the
enable knowing which controls should remain disabled.

Thanks for help. All suggestions are appreciated.
Dan


"G.S." <gs******@gmail.comwrote in message
news:22**********************************@c65g2000 hsa.googlegroups.com...
>Why don't you try redesigning abit. Make the "ZIP form" a user
control. Then on your Customer form center a hidden by default panel.
Then when your logic requires it, Show that panel while disabling the
rest of the controls behind it. The Customer form can still be
minimized, the ZIP *panel* is really part of form's layout, so no
confusion which ZIP panel belongs to which Customer form...
Will that work?

Aug 26 '08 #10

P: n/a
This code exist on the parent. I believe this to be correct based on
several articles I've read.

What code would you propose be placed into the Parent form to open the child
form ?

"raylopez99" <ra********@yahoo.comwrote in message
news:74**********************************@8g2000hs e.googlegroups.com...
On Aug 26, 10:08 am, "Dan Tallent" <s...@microsoft.comwrote:
This code
Child1 C = new Child1();C.StartPosition = FormStartPosition.CenterParent;

C.TopLevel = false;

C.Parent = this;
Well there's your problem right there Dan. You are creating a
potential circular reference with the 'this' pointer on the RHS. By
the logic of your program (if I'm reading it correctly), the child
form has a member variable Parent, and you are essentially saying the
parent is the child. For the root node (first parent to every form,
or Form 1) I guess this is OK, but for every other subform it's not.

Did you program the lunar module that landed (or didn't) on Mars by
any chance?

RL
Aug 27 '08 #11

P: n/a
I did think of that.. but discovered that it would not work. I am at the
very beginning stages of writting this app, but the end result will have
something like 60 unique forms. The big issue will be a user might be in
the middle of working on an invoice and have to open a customer screen for a
completely different customer at the same time. This is a fairly common
scenario with my current app, and I'm trying not to loose this ability for
the rewrite.

I'm suprised this is not a more common question considering the
multi-tasking world we live in.

Thanks again for the help
Dan

"Family Tree Mike" <Fa************@ThisOldHouse.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Have you tried making Customer be an MDI Container? It won't work if
Customer is contained within an MDI Container, but it sounds like what you
are after.

"Dan Tallent" <sp**@microsoft.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>I looked into this method as well. I found I could use a form for the
ZipCode just as easily. The zipcode form can have its Parent set to the
Customer form which elimates the confusion. The form stays within the
boundry of the Customer form, and the Customer (parent) form can still be
minimized. The trick would be that I would need to write code to disable
all of the controls on the form manually. I have older apps that I've
done this with, but I was thinking I was doing this the hard way.

I suppose I could write a routine to loop though all the controls on the
form to disable/enable them. The problem there would be during the
enable knowing which controls should remain disabled.

Thanks for help. All suggestions are appreciated.
Dan


"G.S." <gs******@gmail.comwrote in message
news:22**********************************@c65g200 0hsa.googlegroups.com...
>>Why don't you try redesigning abit. Make the "ZIP form" a user
control. Then on your Customer form center a hidden by default panel.
Then when your logic requires it, Show that panel while disabling the
rest of the controls behind it. The Customer form can still be
minimized, the ZIP *panel* is really part of form's layout, so no
confusion which ZIP panel belongs to which Customer form...
Will that work?


Aug 27 '08 #12

P: n/a
On Aug 26, 9:28*pm, "Dan Tallent" <s...@microsoft.comwrote:
I did think of that.. but discovered that it would not work. *I am at the
very beginning stages of writting this app, but the end result will have
something like 60 unique forms. * The big issue will be a user might bein
the middle of working on an invoice and have to open a customer screen for a
completely different customer at the same time. *This is a fairly common
scenario with my current app, and I'm trying not to loose this ability for
the rewrite.

I'm suprised this is not a more common question considering the
multi-tasking world we live in.

Thanks again for the help
Dan

"Family Tree Mike" <FamilyTreeM...@ThisOldHouse.comwrote in messagenews:%2****************@TK2MSFTNGP05.phx.gb l...
Have you tried making Customer be an MDI Container? *It won't work if
Customer is contained within an MDI Container, but it sounds like what you
are after.
"Dan Tallent" <s...@microsoft.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I looked into this method as well. * I found I could use a form for the
ZipCode just as easily. *The zipcode form can have its Parent set to the
Customer form which elimates the confusion. * The form stays within the
boundry of the Customer form, and the Customer (parent) form can still be
minimized. *The trick would be that I would need to write code to disable
all of the controls on the form manually. *I have older apps that I've
done this with, but I was thinking I was doing this the hard way.
I suppose I could write a routine to loop though all the controls on the
form to disable/enable them. * The problem there would be during the
enable knowing which controls should remain disabled.
Thanks for help. *All suggestions are appreciated.
Dan
"G.S." <gstoy...@gmail.comwrote in message
news:22**********************************@c65g200 0hsa.googlegroups.com....
Why don't you try redesigning abit. Make the "ZIP form" a user
control. Then on your Customer form center a hidden by default panel.
Then when your logic requires it, Show that panel while disabling the
rest of the controls behind it. The Customer form can still be
minimized, the ZIP *panel* is really part of form's layout, so no
confusion which ZIP panel belongs to which Customer form...
Will that work?- Hide quoted text -

- Show quoted text -
I dont know off the top of my head, but I think you could place all
Customer controls in a container, leave the ZIP "modal" panel outside
that container and when you need to disable the Customer controls, you
only disable their container... one line. Now, again, I am not sure of
that and I don't currently have an easy way of checking...
Thinking about it, even if disabling the container doesn't work, the
fact they all belong to the same container (and the ZIP controls
don't) should make your looping strategy straight forward.
Aug 27 '08 #13

P: n/a
On Tue, 26 Aug 2008 18:28:59 -0700, Dan Tallent <sp**@microsoft.comwrote:
I did think of that.. but discovered that it would not work. I am at the
very beginning stages of writting this app, but the end result will have
something like 60 unique forms. The big issue will be a user might be
in
the middle of working on an invoice and have to open a customer screen
for a
completely different customer at the same time. This is a fairly common
scenario with my current app, and I'm trying not to loose this ability
for
the rewrite.

I'm suprised this is not a more common question considering the
multi-tasking world we live in.
All due respect, your intended design is contrary to practices typically
considered appropriate in good user-interface design. That's why it
doesn't come up much.

To recap: you want a window to be modal, but only relative to a particular
parent form, but you don't want there to be any indication that the modal
window is actually parented by that form (i.e. no MDI).

If the "ZIP" form is really modal, then let it be modal: make the user
complete that form before they are allowed to proceed to other input, even
in unrelated windows. This seems to me to be likely to be the best
approach. These modal forms shouldn't really be of the sort that there'd
be any good reason to leave them uncompleted for any lengthy period of
time. That is, modal forms are for specific user input, not something you
just leave lying around for a while.

Conversely, if you want to allow the user to proceed with other input
before completing the "ZIP" form (for example), then don't make it modal.

The fact is, you could in fact get this to work, and without too much
trouble too, by handling the modal behavior explicitly yourself in the
modal window's parent (i.e. disable the form, refuse focus/activation,
etc.) But really, if you've got a form that deserves being modal, then it
deserves to have the user finish using it before they move on to something
else. Doing it otherwise invites the user themselves to become confused
about what they are doing and where _their_ mental focus belongs. The
computer should help them organize their work, not encourage them to
become distracted and lost.

Pete
Aug 27 '08 #14

P: n/a
Yes, the code you posted is the typical way to asign the parent property to
the control.

"Dan Tallent" <sp**@microsoft.comwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
This code exist on the parent. I believe this to be correct based on
several articles I've read.

What code would you propose be placed into the Parent form to open the
child form ?

"raylopez99" <ra********@yahoo.comwrote in message
news:74**********************************@8g2000hs e.googlegroups.com...
On Aug 26, 10:08 am, "Dan Tallent" <s...@microsoft.comwrote:
>This code
Child1 C = new Child1();C.StartPosition = FormStartPosition.CenterParent;

C.TopLevel = false;

C.Parent = this;

Well there's your problem right there Dan. You are creating a
potential circular reference with the 'this' pointer on the RHS. By
the logic of your program (if I'm reading it correctly), the child
form has a member variable Parent, and you are essentially saying the
parent is the child. For the root node (first parent to every form,
or Form 1) I guess this is OK, but for every other subform it's not.

Did you program the lunar module that landed (or didn't) on Mars by
any chance?

RL
Aug 27 '08 #15

P: n/a
On Aug 26, 6:22*pm, "Dan Tallent" <s...@microsoft.comwrote:
This code exist on the parent. * *I believe this to be correct based on
several articles I've read.

What code would you propose be placed into the Parent form to open the child
form ?
If you've seen this work before, then leave it. But I usually do
something like this:

//in parent form:

FormMYCHILD frmChild = new FormMYCHILD();
frmChild.Show()

RL
Aug 27 '08 #16

P: n/a
Unfortunately this code does not place the new (child) form within the
parent itself. It is free to move everywhere including out of your
application and to the desktop.

Dan

"raylopez99" <ra********@yahoo.comwrote in message
news:26**********************************@59g2000h sb.googlegroups.com...
On Aug 26, 6:22 pm, "Dan Tallent" <s...@microsoft.comwrote:
This code exist on the parent. I believe this to be correct based on
several articles I've read.

What code would you propose be placed into the Parent form to open the
child
form ?
If you've seen this work before, then leave it. But I usually do
something like this:

//in parent form:

FormMYCHILD frmChild = new FormMYCHILD();
frmChild.Show()

RL
Aug 27 '08 #17

P: n/a
I think the loop with have to have a condition within it to ignore child
forms. I haven't written this code yet, but it seems likely.
Thanks for the help
Dan

"G.S." <gs******@gmail.comwrote in message
news:6b**********************************@a70g2000 hsh.googlegroups.com...
On Aug 26, 9:28 pm, "Dan Tallent" <s...@microsoft.comwrote:
I did think of that.. but discovered that it would not work. I am at the
very beginning stages of writting this app, but the end result will have
something like 60 unique forms. The big issue will be a user might be in
the middle of working on an invoice and have to open a customer screen for
a
completely different customer at the same time. This is a fairly common
scenario with my current app, and I'm trying not to loose this ability for
the rewrite.

I'm suprised this is not a more common question considering the
multi-tasking world we live in.

Thanks again for the help
Dan

"Family Tree Mike" <FamilyTreeM...@ThisOldHouse.comwrote in
messagenews:%2****************@TK2MSFTNGP05.phx.gb l...
Have you tried making Customer be an MDI Container? It won't work if
Customer is contained within an MDI Container, but it sounds like what
you
are after.
"Dan Tallent" <s...@microsoft.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I looked into this method as well. I found I could use a form for the
ZipCode just as easily. The zipcode form can have its Parent set to the
Customer form which elimates the confusion. The form stays within the
boundry of the Customer form, and the Customer (parent) form can still
be
minimized. The trick would be that I would need to write code to disable
all of the controls on the form manually. I have older apps that I've
done this with, but I was thinking I was doing this the hard way.
I suppose I could write a routine to loop though all the controls on
the
form to disable/enable them. The problem there would be during the
enable knowing which controls should remain disabled.
Thanks for help. All suggestions are appreciated.
Dan
"G.S." <gstoy...@gmail.comwrote in message
news:22**********************************@c65g200 0hsa.googlegroups.com...
Why don't you try redesigning abit. Make the "ZIP form" a user
control. Then on your Customer form center a hidden by default panel.
Then when your logic requires it, Show that panel while disabling the
rest of the controls behind it. The Customer form can still be
minimized, the ZIP *panel* is really part of form's layout, so no
confusion which ZIP panel belongs to which Customer form...
Will that work?- Hide quoted text -

- Show quoted text -
I dont know off the top of my head, but I think you could place all
Customer controls in a container, leave the ZIP "modal" panel outside
that container and when you need to disable the Customer controls, you
only disable their container... one line. Now, again, I am not sure of
that and I don't currently have an easy way of checking...
Thinking about it, even if disabling the container doesn't work, the
fact they all belong to the same container (and the ZIP controls
don't) should make your looping strategy straight forward.

Aug 27 '08 #18

P: n/a
I am new to Windows form design in C#, and I fully admit I may be doing some
things wrong. This is why I am here getting advise from my peers. I have
searched hundreds of websites over the last week but felt like many people
ask the questions without receiving an acceptable answer. Many times the
people who initially posted the question never write in to report what
solution they found.
With that said....

I don't want the child form to be "modal" in the traditional sense because
it forces the user to finish and close this screen before they can work
anywhere else within the program.

You wrote:
To recap: you want a window to be modal, but only relative to a particular
parent form, but you don't want there to be any indication that the modal
window is actually parented by that form (i.e. no MDI).
This is not entirely correct. I don't want the form to be modal, however I
do not want the parent form editable while this (child) form is open. I
definately would prefer the child form to reside within the parent. I feel
the user interface would be clumsy and difficult to navigate otherwise.

My application will have its main MDI form that the entire application works
within. I don't want forms outside of the main MDI form. This MDI form
will have many child forms (Customer, Invoice, etc). These forms (Customer,
Invoice, etc) will have child forms of their own. (ZipCode, etc). Forms
like the Invoice form will have subforms that will be used for additional
data entry for the specific invoice. This type of interface is not
dissimilar to an Advanced button on many applications today. The average
user won't drill into this form, but sometimes the user will need use of
these Advanced features.
If I made these subforms modal then the user would be required to finish any
data entry before they could move anywhere else in the program. If the
phone rings and they need to look up a Customer, do you suggest they abandon
the changes on the subform so they can look up this customer? I feel they
should be able to open another instance of the Customer form to look up this
Customer who is calling.

Thanks
Dan


"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Tue, 26 Aug 2008 18:28:59 -0700, Dan Tallent <sp**@microsoft.com>
wrote:
>I did think of that.. but discovered that it would not work. I am at the
very beginning stages of writting this app, but the end result will have
something like 60 unique forms. The big issue will be a user might be
in
the middle of working on an invoice and have to open a customer screen
for a
completely different customer at the same time. This is a fairly common
scenario with my current app, and I'm trying not to loose this ability
for
the rewrite.

I'm suprised this is not a more common question considering the
multi-tasking world we live in.

All due respect, your intended design is contrary to practices typically
considered appropriate in good user-interface design. That's why it
doesn't come up much.

To recap: you want a window to be modal, but only relative to a particular
parent form, but you don't want there to be any indication that the modal
window is actually parented by that form (i.e. no MDI).

If the "ZIP" form is really modal, then let it be modal: make the user
complete that form before they are allowed to proceed to other input, even
in unrelated windows. This seems to me to be likely to be the best
approach. These modal forms shouldn't really be of the sort that there'd
be any good reason to leave them uncompleted for any lengthy period of
time. That is, modal forms are for specific user input, not something you
just leave lying around for a while.

Conversely, if you want to allow the user to proceed with other input
before completing the "ZIP" form (for example), then don't make it modal.

The fact is, you could in fact get this to work, and without too much
trouble too, by handling the modal behavior explicitly yourself in the
modal window's parent (i.e. disable the form, refuse focus/activation,
etc.) But really, if you've got a form that deserves being modal, then it
deserves to have the user finish using it before they move on to something
else. Doing it otherwise invites the user themselves to become confused
about what they are doing and where _their_ mental focus belongs. The
computer should help them organize their work, not encourage them to
become distracted and lost.

Pete

Aug 27 '08 #19

P: n/a
On Aug 27, 7:50*am, "Dan Tallent" <s...@microsoft.comwrote:
I think the loop with have to have a condition within it to ignore child
forms. *I haven't written this code yet, but it seems likely.
Thanks for the help
Dan

"G.S." <gstoy...@gmail.comwrote in message

news:6b**********************************@a70g2000 hsh.googlegroups.com...
On Aug 26, 9:28 pm, "Dan Tallent" <s...@microsoft.comwrote:


I did think of that.. but discovered that it would not work. I am at the
very beginning stages of writting this app, but the end result will have
something like 60 unique forms. The big issue will be a user might be in
the middle of working on an invoice and have to open a customer screen for
a
completely different customer at the same time. This is a fairly common
scenario with my current app, and I'm trying not to loose this ability for
the rewrite.
I'm suprised this is not a more common question considering the
multi-tasking world we live in.
Thanks again for the help
Dan
"Family Tree Mike" <FamilyTreeM...@ThisOldHouse.comwrote in
messagenews:%2****************@TK2MSFTNGP05.phx.gb l...
Have you tried making Customer be an MDI Container? It won't work if
Customer is contained within an MDI Container, but it sounds like what
you
are after.
"Dan Tallent" <s...@microsoft.comwrote in message
>news:%2****************@TK2MSFTNGP04.phx.gbl...
>>I looked into this method as well. I found I could use a form for the
>>ZipCode just as easily. The zipcode form can have its Parent set to the
>>Customer form which elimates the confusion. The form stays within the
>>boundry of the Customer form, and the Customer (parent) form can still
>>be
>>minimized. The trick would be that I would need to write code to disable
>>all of the controls on the form manually. I have older apps that I've
>>done this with, but I was thinking I was doing this the hard way.
>I suppose I could write a routine to loop though all the controls on
>the
>form to disable/enable them. The problem there would be during the
>enable knowing which controls should remain disabled.
>Thanks for help. All suggestions are appreciated.
>Dan
>"G.S." <gstoy...@gmail.comwrote in message
>>news:22**********************************@c65g20 00hsa.googlegroups.com...
>>Why don't you try redesigning abit. Make the "ZIP form" a user
>>control. Then on your Customer form center a hidden by default panel.
>>Then when your logic requires it, Show that panel while disabling the
>>rest of the controls behind it. The Customer form can still be
>>minimized, the ZIP *panel* is really part of form's layout, so no
>>confusion which ZIP panel belongs to which Customer form...
>>Will that work?- Hide quoted text -
- Show quoted text -

I dont know off the top of my head, but I think you could place all
Customer controls in a container, leave the ZIP "modal" panel outside
that container and when you need to disable the Customer controls, you
only disable their container... one line. Now, again, I am not sure of
that and I don't currently have an easy way of checking...
Thinking about it, even if disabling the container doesn't work, the
fact they all belong to the same container (and the ZIP controls
don't) should make your looping strategy straight forward.- Hide quoted text -

- Show quoted text -
While I agree to a degree with Peter Duniho on the possibility of
cluttered screen, I think that keeping the ZIP as a panel inside the
form diminishes that clutter.

And yes, the panel does have Enabled property.

Here's a working example. button1 is on the "main" form and switches
to modal panel, button2 is on the modal panel and switches back to
main form view. Of course you can play with panel positions.

using System;
using System.Windows.Forms;

namespace ModalPanel
{
public class Form1 : Form
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
ShowModalPanel(true);
}

private void button2_Click(object sender, EventArgs e)
{
ShowModalPanel(false);
}

private void ShowModalPanel(bool show)
{
panelMainForm.Enabled = !show;
panelModal.Visible = show;
}

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panelMainForm = new System.Windows.Forms.Panel();
this.panelModal = new System.Windows.Forms.Panel();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.panelMainForm.SuspendLayout();
this.panelModal.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// panelMainForm
//
this.panelMainForm.Controls.Add(this.label1);
this.panelMainForm.Controls.Add(this.button1);
this.panelMainForm.Controls.Add(this.groupBox1);
this.panelMainForm.Location = new System.Drawing.Point(34, 30);
this.panelMainForm.Name = "panelMainForm";
this.panelMainForm.Size = new System.Drawing.Size(292, 361);
this.panelMainForm.TabIndex = 0;
//
// panelModal
//
this.panelModal.Controls.Add(this.button2);
this.panelModal.Controls.Add(this.textBox2);
this.panelModal.Controls.Add(this.checkBox1);
this.panelModal.Location = new System.Drawing.Point(332, 124);
this.panelModal.Name = "panelModal";
this.panelModal.Size = new System.Drawing.Size(200, 141);
this.panelModal.TabIndex = 0;
this.panelModal.Visible = false;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(37, 74);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(80, 17);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.comboBox1);
this.groupBox1.Controls.Add(this.checkBox2);
this.groupBox1.Location = new System.Drawing.Point(15, 44);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(261, 125);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 295);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(7, 20);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(80, 17);
this.checkBox2.TabIndex = 0;
this.checkBox2.Text = "checkBox2";
this.checkBox2.UseVisualStyleBackColor = true;
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(7, 44);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(15, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(97, 13);
this.label1.TabIndex = 2;
this.label1.Text = "label1 label1 label1";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(7, 72);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 2;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(37, 42);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 1;
//
// button2
//
this.button2.Location = new System.Drawing.Point(41, 108);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(543, 433);
this.Controls.Add(this.panelModal);
this.Controls.Add(this.panelMainForm);
this.Name = "Form1";
this.Text = "Form1";
this.panelMainForm.ResumeLayout(false);
this.panelMainForm.PerformLayout();
this.panelModal.ResumeLayout(false);
this.panelModal.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Panel panelMainForm;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.Panel panelModal;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button button2;
}
}
Aug 27 '08 #20

P: n/a
I appreciate the help.

I currently have code that is using a child form (ZipCode) within the parent
(Customer)

When the child closes the parent comes back to life. The child has its
FormBorderStyle = FixedToolWindow and cannot move outside the area of the
parent (Customer).
This approach seems to be working. It also allows me to use the ZipCode
form in other locations within the program such as for a Vendors address.
If the Customer form is minimized or moved the ZipCode form travels with it.
I am thinking of using an Inherited version of the form class so I can add
the Active method for use in all of the forms.

I have not attempted to Inherit from a control before and I'm not sure how I
will be able to use it within the IDE.....yet.

Thanks everyone for your help. If you see any problems with this approach
please feel free to point them out.

Thanks again,
Dan
//---------------------------------------------------------------------------

private void button4_Click(object sender, EventArgs e)

{

this.Active(false);

Child1 C = new Child1();

C.FormClosed+=new FormClosedEventHandler(C_FormClosed);

C.TopLevel = false;
C.Parent = this;

C.Top = (this.MdiParent.Top + (this.Height - C.Height) / 2);

C.Left = (this.MdiParent.Left + (this.Width - C.Width) / 2);

C.BringToFront();

C.Show();

}

void C_FormClosed(object sender, FormClosedEventArgs e)

{
this.Active(true);
}

private void Active(bool status)

{

foreach (Control oControl in this.Controls)

{

oControl.Enabled = status;
}

}

//---------------------------------------------------------------------------



"G.S." <gs******@gmail.comwrote in message
news:7c**********************************@m45g2000 hsb.googlegroups.com...
On Aug 27, 7:50 am, "Dan Tallent" <s...@microsoft.comwrote:
I think the loop with have to have a condition within it to ignore child
forms. I haven't written this code yet, but it seems likely.
Thanks for the help
Dan

"G.S." <gstoy...@gmail.comwrote in message

news:6b**********************************@a70g2000 hsh.googlegroups.com...
On Aug 26, 9:28 pm, "Dan Tallent" <s...@microsoft.comwrote:


I did think of that.. but discovered that it would not work. I am at the
very beginning stages of writting this app, but the end result will have
something like 60 unique forms. The big issue will be a user might be in
the middle of working on an invoice and have to open a customer screen
for
a
completely different customer at the same time. This is a fairly common
scenario with my current app, and I'm trying not to loose this ability
for
the rewrite.
I'm suprised this is not a more common question considering the
multi-tasking world we live in.
Thanks again for the help
Dan
"Family Tree Mike" <FamilyTreeM...@ThisOldHouse.comwrote in
messagenews:%2****************@TK2MSFTNGP05.phx.gb l...
Have you tried making Customer be an MDI Container? It won't work if
Customer is contained within an MDI Container, but it sounds like what
you
are after.
"Dan Tallent" <s...@microsoft.comwrote in message
>news:%2****************@TK2MSFTNGP04.phx.gbl...
>>I looked into this method as well. I found I could use a form for the
>>ZipCode just as easily. The zipcode form can have its Parent set to
>>the
>>Customer form which elimates the confusion. The form stays within the
>>boundry of the Customer form, and the Customer (parent) form can still
>>be
>>minimized. The trick would be that I would need to write code to
>>disable
>>all of the controls on the form manually. I have older apps that I've
>>done this with, but I was thinking I was doing this the hard way.
>I suppose I could write a routine to loop though all the controls on
>the
>form to disable/enable them. The problem there would be during the
>enable knowing which controls should remain disabled.
>Thanks for help. All suggestions are appreciated.
>Dan
>"G.S." <gstoy...@gmail.comwrote in message
>>news:22**********************************@c65g20 00hsa.googlegroups.com...
>>Why don't you try redesigning abit. Make the "ZIP form" a user
>>control. Then on your Customer form center a hidden by default
>>panel.
>>Then when your logic requires it, Show that panel while disabling
>>the
>>rest of the controls behind it. The Customer form can still be
>>minimized, the ZIP *panel* is really part of form's layout, so no
>>confusion which ZIP panel belongs to which Customer form...
>>Will that work?- Hide quoted text -
- Show quoted text -

I dont know off the top of my head, but I think you could place all
Customer controls in a container, leave the ZIP "modal" panel outside
that container and when you need to disable the Customer controls, you
only disable their container... one line. Now, again, I am not sure of
that and I don't currently have an easy way of checking...
Thinking about it, even if disabling the container doesn't work, the
fact they all belong to the same container (and the ZIP controls
don't) should make your looping strategy straight forward.- Hide quoted
text -

- Show quoted text -
While I agree to a degree with Peter Duniho on the possibility of
cluttered screen, I think that keeping the ZIP as a panel inside the
form diminishes that clutter.

And yes, the panel does have Enabled property.

Here's a working example. button1 is on the "main" form and switches
to modal panel, button2 is on the modal panel and switches back to
main form view. Of course you can play with panel positions.

using System;
using System.Windows.Forms;

namespace ModalPanel
{
public class Form1 : Form
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
ShowModalPanel(true);
}

private void button2_Click(object sender, EventArgs e)
{
ShowModalPanel(false);
}

private void ShowModalPanel(bool show)
{
panelMainForm.Enabled = !show;
panelModal.Visible = show;
}

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panelMainForm = new System.Windows.Forms.Panel();
this.panelModal = new System.Windows.Forms.Panel();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.panelMainForm.SuspendLayout();
this.panelModal.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// panelMainForm
//
this.panelMainForm.Controls.Add(this.label1);
this.panelMainForm.Controls.Add(this.button1);
this.panelMainForm.Controls.Add(this.groupBox1);
this.panelMainForm.Location = new System.Drawing.Point(34, 30);
this.panelMainForm.Name = "panelMainForm";
this.panelMainForm.Size = new System.Drawing.Size(292, 361);
this.panelMainForm.TabIndex = 0;
//
// panelModal
//
this.panelModal.Controls.Add(this.button2);
this.panelModal.Controls.Add(this.textBox2);
this.panelModal.Controls.Add(this.checkBox1);
this.panelModal.Location = new System.Drawing.Point(332, 124);
this.panelModal.Name = "panelModal";
this.panelModal.Size = new System.Drawing.Size(200, 141);
this.panelModal.TabIndex = 0;
this.panelModal.Visible = false;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(37, 74);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(80, 17);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.comboBox1);
this.groupBox1.Controls.Add(this.checkBox2);
this.groupBox1.Location = new System.Drawing.Point(15, 44);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(261, 125);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 295);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(7, 20);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(80, 17);
this.checkBox2.TabIndex = 0;
this.checkBox2.Text = "checkBox2";
this.checkBox2.UseVisualStyleBackColor = true;
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(7, 44);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(15, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(97, 13);
this.label1.TabIndex = 2;
this.label1.Text = "label1 label1 label1";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(7, 72);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 2;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(37, 42);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 1;
//
// button2
//
this.button2.Location = new System.Drawing.Point(41, 108);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(543, 433);
this.Controls.Add(this.panelModal);
this.Controls.Add(this.panelMainForm);
this.Name = "Form1";
this.Text = "Form1";
this.panelMainForm.ResumeLayout(false);
this.panelMainForm.PerformLayout();
this.panelModal.ResumeLayout(false);
this.panelModal.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Panel panelMainForm;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.Panel panelModal;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button button2;
}
}
Aug 27 '08 #21

P: n/a
I just realized I used the MdiParent property for setting this location.
This was something I was playing with. It should just be Parent
"Dan Tallent" <sp**@microsoft.comwrote in message
news:O7**************@TK2MSFTNGP05.phx.gbl...
>I appreciate the help.

I currently have code that is using a child form (ZipCode) within the
parent (Customer)

When the child closes the parent comes back to life. The child has its
FormBorderStyle = FixedToolWindow and cannot move outside the area of the
parent (Customer).
This approach seems to be working. It also allows me to use the ZipCode
form in other locations within the program such as for a Vendors address.
If the Customer form is minimized or moved the ZipCode form travels with
it. I am thinking of using an Inherited version of the form class so I can
add the Active method for use in all of the forms.

I have not attempted to Inherit from a control before and I'm not sure how
I will be able to use it within the IDE.....yet.

Thanks everyone for your help. If you see any problems with this
approach please feel free to point them out.

Thanks again,
Dan
//---------------------------------------------------------------------------

private void button4_Click(object sender, EventArgs e)

{

this.Active(false);

Child1 C = new Child1();

C.FormClosed+=new FormClosedEventHandler(C_FormClosed);

C.TopLevel = false;
C.Parent = this;

C.Top = (this.MdiParent.Top + (this.Height - C.Height) / 2);

C.Left = (this.MdiParent.Left + (this.Width - C.Width) / 2);

C.BringToFront();

C.Show();

}

void C_FormClosed(object sender, FormClosedEventArgs e)

{
this.Active(true);
}

private void Active(bool status)

{

foreach (Control oControl in this.Controls)

{

oControl.Enabled = status;
}

}

//---------------------------------------------------------------------------



"G.S." <gs******@gmail.comwrote in message
news:7c**********************************@m45g2000 hsb.googlegroups.com...
On Aug 27, 7:50 am, "Dan Tallent" <s...@microsoft.comwrote:
>I think the loop with have to have a condition within it to ignore child
forms. I haven't written this code yet, but it seems likely.
Thanks for the help
Dan

"G.S." <gstoy...@gmail.comwrote in message

news:6b**********************************@a70g200 0hsh.googlegroups.com...
On Aug 26, 9:28 pm, "Dan Tallent" <s...@microsoft.comwrote:


I did think of that.. but discovered that it would not work. I am at
the
very beginning stages of writting this app, but the end result will
have
something like 60 unique forms. The big issue will be a user might be
in
the middle of working on an invoice and have to open a customer screen
for
a
completely different customer at the same time. This is a fairly common
scenario with my current app, and I'm trying not to loose this ability
for
the rewrite.
I'm suprised this is not a more common question considering the
multi-tasking world we live in.
Thanks again for the help
Dan
"Family Tree Mike" <FamilyTreeM...@ThisOldHouse.comwrote in
messagenews:%2****************@TK2MSFTNGP05.phx.gb l...
Have you tried making Customer be an MDI Container? It won't work if
Customer is contained within an MDI Container, but it sounds like
what
you
are after.
"Dan Tallent" <s...@microsoft.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
I looked into this method as well. I found I could use a form for the
ZipCode just as easily. The zipcode form can have its Parent set to
the
Customer form which elimates the confusion. The form stays within the
boundry of the Customer form, and the Customer (parent) form can
still
be
minimized. The trick would be that I would need to write code to
disable
all of the controls on the form manually. I have older apps that I've
done this with, but I was thinking I was doing this the hard way.
>I suppose I could write a routine to loop though all the controls on
the
form to disable/enable them. The problem there would be during the
enable knowing which controls should remain disabled.
>Thanks for help. All suggestions are appreciated.
Dan
>"G.S." <gstoy...@gmail.comwrote in message
news:22**********************************@c65g20 00hsa.googlegroups.com...
Why don't you try redesigning abit. Make the "ZIP form" a user
control. Then on your Customer form center a hidden by default
panel.
Then when your logic requires it, Show that panel while disabling
the
rest of the controls behind it. The Customer form can still be
minimized, the ZIP *panel* is really part of form's layout, so no
confusion which ZIP panel belongs to which Customer form...
Will that work?- Hide quoted text -
- Show quoted text -

I dont know off the top of my head, but I think you could place all
Customer controls in a container, leave the ZIP "modal" panel outside
that container and when you need to disable the Customer controls, you
only disable their container... one line. Now, again, I am not sure of
that and I don't currently have an easy way of checking...
Thinking about it, even if disabling the container doesn't work, the
fact they all belong to the same container (and the ZIP controls
don't) should make your looping strategy straight forward.- Hide quoted
text -

- Show quoted text -

While I agree to a degree with Peter Duniho on the possibility of
cluttered screen, I think that keeping the ZIP as a panel inside the
form diminishes that clutter.

And yes, the panel does have Enabled property.

Here's a working example. button1 is on the "main" form and switches
to modal panel, button2 is on the modal panel and switches back to
main form view. Of course you can play with panel positions.

using System;
using System.Windows.Forms;

namespace ModalPanel
{
public class Form1 : Form
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
ShowModalPanel(true);
}

private void button2_Click(object sender, EventArgs e)
{
ShowModalPanel(false);
}

private void ShowModalPanel(bool show)
{
panelMainForm.Enabled = !show;
panelModal.Visible = show;
}

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panelMainForm = new System.Windows.Forms.Panel();
this.panelModal = new System.Windows.Forms.Panel();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.panelMainForm.SuspendLayout();
this.panelModal.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// panelMainForm
//
this.panelMainForm.Controls.Add(this.label1);
this.panelMainForm.Controls.Add(this.button1);
this.panelMainForm.Controls.Add(this.groupBox1);
this.panelMainForm.Location = new System.Drawing.Point(34, 30);
this.panelMainForm.Name = "panelMainForm";
this.panelMainForm.Size = new System.Drawing.Size(292, 361);
this.panelMainForm.TabIndex = 0;
//
// panelModal
//
this.panelModal.Controls.Add(this.button2);
this.panelModal.Controls.Add(this.textBox2);
this.panelModal.Controls.Add(this.checkBox1);
this.panelModal.Location = new System.Drawing.Point(332, 124);
this.panelModal.Name = "panelModal";
this.panelModal.Size = new System.Drawing.Size(200, 141);
this.panelModal.TabIndex = 0;
this.panelModal.Visible = false;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(37, 74);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(80, 17);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.comboBox1);
this.groupBox1.Controls.Add(this.checkBox2);
this.groupBox1.Location = new System.Drawing.Point(15, 44);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(261, 125);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 295);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(7, 20);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(80, 17);
this.checkBox2.TabIndex = 0;
this.checkBox2.Text = "checkBox2";
this.checkBox2.UseVisualStyleBackColor = true;
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(7, 44);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(15, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(97, 13);
this.label1.TabIndex = 2;
this.label1.Text = "label1 label1 label1";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(7, 72);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 2;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(37, 42);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 1;
//
// button2
//
this.button2.Location = new System.Drawing.Point(41, 108);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(543, 433);
this.Controls.Add(this.panelModal);
this.Controls.Add(this.panelMainForm);
this.Name = "Form1";
this.Text = "Form1";
this.panelMainForm.ResumeLayout(false);
this.panelMainForm.PerformLayout();
this.panelModal.ResumeLayout(false);
this.panelModal.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Panel panelMainForm;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.Panel panelModal;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button button2;
}
}

Aug 27 '08 #22

This discussion thread is closed

Replies have been disabled for this discussion.