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

Sub Form Cleanup

Using C# 3.5

I have a form that calls many other sub-forms. Typically there will be
five forms open at the same time.

If the main form is closed all the sub forms are also closed.

Is there a standard way to gain control within the sub-forms to do
individual clean-up prior to their removal?

.... Thom
__________________________________________________ _
Thom Little - www.tlanet.net - Thom Little Associates, Ltd.
Jun 27 '08 #1
6 2236
Got it.

I was trying to capture it in the sub-forms and it must be done in the main
form.

(My only excuse ... sleep depravation.)

.... Thom
__________________________________________________ _
Thom Little - www.tlanet.net - Thom Little Associates, Ltd.
Jun 27 '08 #2
On Tue, 13 May 2008 08:56:52 -0700, Thom Little <th**@tlanet.netwrote:
Using C# 3.5

I have a form that calls many other sub-forms. Typically there will be
five forms open at the same time.

If the main form is closed all the sub forms are also closed.

Is there a standard way to gain control within the sub-forms to do
individual clean-up prior to their removal?
You can override OnFormClosing() or OnFormClosed() in each sub-form to
detect when they are closed and do your necessary processing there.

I'm assuming that it's okay for all of the sub-forms to be closed when the
main form is closed. If that's not desirable behavior, you can change
that by not passing a specific form instance to Application.Run() in your
Program.cs file (just create and show the form and then call
Application.Run() without a parameter).

Pete
Jun 27 '08 #3
That is a simply great idea that I will keep in mind.

Unfortunately in this particular case the same sub-form generates four
variations based on a simple string that is passed to it.

For that reason I need to retain control on the main form. (4 shows and 4
closes)

Thanks for the help.

.... Thom
__________________________________________________ _
Thom Little - www.tlanet.net - Thom Little Associates, Ltd.
Jun 27 '08 #4
On Tue, 13 May 2008 15:29:28 -0700, Thom Little <th**@tlanet.netwrote:
That is a simply great idea that I will keep in mind.

Unfortunately in this particular case the same sub-form generates four
variations based on a simple string that is passed to it.

For that reason I need to retain control on the main form. (4 shows and 4
closes)
I don't follow your logic. Just because you have four different instances
of the same class based on four different inputs, that doesn't mean you
can't handle "close" processing within that class. And IMHO, if the
processing is specific to each instance, then the processing belongs in
the sub-form class. Putting sub-form logic into the main form is contrary
to basic OOP design.

Pete
Jun 27 '08 #5
I was being imprecise (and perhaps dim).

There is one main form and one sub-form. There are four possible
permutations of how the sub-form is rendered. There can be one copy of each
sub-from. So lets call them A, B, C, and D.

Everything about how each is rendered is contained in the sub-form. The
definition of the six sub-forms in this example I think has to be in the
main form. There will a maximum of four calls to load the appropriate
versions and a maximum of four calls to close them all located in the main
form.

I capture the position where each sub-form is loaded when the main form is
shutdown and save them in the Registry. On reload, I restore the sub-forms
to where they were.

The nicest thing would be to have the sub-form pump out 0 to 4 updates to
the Registry when the main form is closed. I currently do that by
maintaining the instance in the main form and issue the appropriate sub-form
close calls on shutdown.

Am I missing something?

.... Thom
__________________________________________________ _
Thom Little - www.tlanet.net - Thom Little Associates, Ltd.
Jun 27 '08 #6
On Wed, 14 May 2008 12:11:07 -0700, Thom Little <th**@tlanet.netwrote:
I was being imprecise (and perhaps dim).
Well, let's see if we can get the terminology correct.
There is one main form and one sub-form.
Do you mean "one main form class" and "one sub-form class"?
There are four possible
permutations of how the sub-form is rendered.
The word "rendered" usually implies a single visual update to the screen.
Are you saying that the "one sub-form class" will display itself in one of
four different ways depending on how it's initialized?
There can be one copy of each sub-from.
When you write "copy" do you really mean "instance"? When you write
"sub-form", do you mean (as above) "sub-form class"? If there is only
"one sub-form class", then what does it mean for there to be one copy "of
each sub-form class"?
So lets call them A, B, C, and D.

Everything about how each is rendered is contained in the sub-form.
If by "sub-form" you really mean "sub-form class", why does a single class
contain logic for displaying four different presentations? Wouldn't it be
more logical to have a different class for each presentation?
The
definition of the six sub-forms in this example I think has to be in the
main form.
What "definition"? And how do you get "six sub-forms"? Above, you only
have named four ("A, B, C, and D").
There will a maximum of four calls to load the appropriate
versions and a maximum of four calls to close them all located in the
main
form.
I understand that if there are to be four different instances of a form
class, you will need to make four calls to instantiate them. But as each
instance can itself monitor when it's closed, I don't see why the main
form need concern itself with that.
I capture the position where each sub-form is loaded when the main form
is
shutdown and save them in the Registry. On reload, I restore the
sub-forms
to where they were.
For saving location of each sub-form instance, it seems to me that _all_
of that logic can be places in the sub-form class. There should be no
need for the main form to concern itself with any of that, except perhaps
to provide to the sub-form class a storage container for storing the
location (in the event, for example, that you might have more than one
"main form" instance and you want each instance to be able to manage its
own sub-form instances separately).
The nicest thing would be to have the sub-form pump out 0 to 4 updates to
the Registry when the main form is closed.
In a .NET application, it is generally considered more appropriate to use
the configuration file API to store user state, settings, etc. The
registry isn't quite deprecated, but it might as well be.

In any case, I agree that "the nicest thing" would be to have the sub-form
class deal with saving the data. That's what I'm trying to say.
I currently do that by
maintaining the instance in the main form and issue the appropriate
sub-form
close calls on shutdown.
By default, closing your main form (that is, the form that is passed to
the Application.Run() method) will shut down the application, closing any
other forms in the process. You should not need to maintain any
references to the sub-forms (for this purpose, at any rate), as the forms
should be closed anyway. And of course, when the sub-forms are closed
implicitly by the closure of the main form, you can handle that in the
sub-form by overriding OnFormClosed().
Am I missing something?
You tell me. :)

It's very difficult to really understand what you're doing without an
appropriate concise-but-complete code sample that demonstrates exactly
what you're trying to do. Of particular amiguity is why you have a single
sub-form class that nevertheless is apparently used in four different
ways. But assuming that what you're doing is normal "user state
persistence", the basic question of whether the logic should go in the
main form or the sub-form class seems to be clearly on the "in the
sub-form class" side. I've seen nothing in this thread so far to suggest
that the logic belongs in the main class, never mind needs to be there.

Pete
Jun 27 '08 #7

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

Similar topics

6
by: use dmgass at hotmail dot com | last post by:
I'm writing a module and when it is imported by a script I want some code automatically executed when the importing script is finished executing. I'd like it to execute before interactive mode is...
3
by: Bill | last post by:
I'm using the POST method to submit a simple form html page with yes/no and checkbox fields to an asp response page which stores the values in a new dim string, then uses it to build a new table...
2
by: rdemyan via AccessMonster.com | last post by:
I have a custom message form that I want to display when the user shuts down my app. Some clean up needs to be done during shutdown and I want to display this form and then display various...
2
by: Giuseppe | last post by:
Hi everybody, this is my first post in this group since it is from little time that I have begun to learn c++. My problem is to post a web form using the libcurl library. The form is at this...
1
by: Jason S | last post by:
I haven't used try/catch/finally very much in Javascript. My function (let's call it try_it()) needs to call a function that could throw an exception (let's call it dangerous()) with some setup()...
69
by: MQ | last post by:
Hi all I am just wondering how most people implement cleanup in C functions. In particular, if the function opens a number of resources, these need to be released properly should an error occur...
6
by: Greg Strong | last post by:
Hello All, Is is possible to use an ADO recordset to populate an unbound continuous Subform? I've done some Googling without much luck, so this maybe impossible, but let me try to explain...
3
by: Petr Pavlu | last post by:
Hello, I have two questions how the functions should be written. I read the FAQ but didn't find any answer. If there is any please point me out. I. Cleanup code Consider I have to open file1,...
6
by: Peter Michaux | last post by:
I just ran some circular memory leak tests in IE6, O9, S3, FF2 and it seems to me they all benefit from doing the same kind of circular memory leak cleanup that IE requires. My tests were very...
4
by: IanWright | last post by:
I've got a section of a program that I can't quite get to work. I'm fairly sure its something very simple/trivial but it looks correct to me, so if someone could help me fix the problem, and explain...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.