473,722 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2271
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.ne twrote:
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.ne twrote:
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.ne twrote:
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
1469
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 entered when executing the importing script from the command line. I don't want to have to impose that the importing script must call a function at it's end. Any help is greatly appreciated!!
3
2336
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 using ADO. I'm getting sometimes correct values, sometimes null values (when I know I pass a valid default value) and other times multiple values! I know what the values coming over are because I do a response.write to see it before the error...
2
2561
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 messages in the label on the form as the shutdown cleanup proceeds. I have a hidden Startup form. So in the Startup form OnClose event, I am loading the message form and then changing the label caption as the code proceeds to do the cleanup of...
2
6717
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 address: http://it.mobi.dada.net/lostpassword.php end it isn't very complicated: <form method="post" action="/cgi-bin/hotw/sendpassword.chm">
1
4580
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() beforehand and cleanup() afterwards. What I want to make sure cleanup() is called whether or not dangerous throws an exception, and if it does throw an exception, rethrow the exception to whatever is calling try_it(). In C++ this is much easier...
69
3221
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 at any point in the function (as well as at the end if successful). C++ has exceptions, the only way I can see to do this neatly in C is to use goto statements. Is my method of implementing cleanup good, or are their better ways. Here is an...
6
4871
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 why. I've been exploring using Access as a front end to both SQL MSDE and Oracle XE. I'm in the process of writing a class to handle the basics of the ADO connection and recordsets. The basic relationships are as follows:
3
3621
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, then make some malloc and then open file2. What is the best solution how to write the cleanup code? See my pseudo- code ideas.
6
1878
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 similar to Richard Cornford's which are very easy to set up and watch run. <URL: http://groups.google.com/group/comp.lang.javascript/msg/e723d3324aaa4127> On my machine, O, S, and FF all level off at around 38MB of RAM while
4
2663
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 what it is that is wrong, that would be great... I've posted a sample of code, which is the bit of interest: class Solution { private: int *HeuristicTours; public: int* GetTours() {
0
8740
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9158
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8059
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6685
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3208
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2148
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.