Solved

Trying to savesettings on form close but not able to get values from controls.

Posted on 2004-10-12
11
204 Views
Last Modified: 2010-04-23
OK I have a form myForm with a user control on it called myControl. I have a variety of control values on myControl which I load from the registry in the constuctor using getSetting.

WHen myForm is closed, it takes myControl with it. At this point I want to saveSettings for each of the controls on myControl so that the changes the user made are not lost.

I have a sub saveAllSettings which I have tried placing in the finalize and in the dispose methods, but when it comes to saveSetting reading textBox1.text, the textbox.text value is empty, when there was definately some text htere before.

Is there no good time to run save settings? Do I need to make a save button/wire it up to events, or can I do it automatically on form close as I wish? I dont want to make a public method and have myForm call it.
0
Comment
Question by:mcintyre321
  • 4
  • 2
  • 2
  • +1
11 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12285228
See Dispose needs to be called explicitly and Finalize is not reliable, you don't know when it would be called.

I think it is better if you call your SaveAllSettings Function in Form_Closing event
0
 
LVL 9

Expert Comment

by:checoo
ID: 12285231
why dont you write the code in form closing event..??
0
 

Author Comment

by:mcintyre321
ID: 12285251
its not a form - its a UserControl which doesn't have form_closing I dont think...
0
 
LVL 9

Expert Comment

by:checoo
ID: 12285312
but your question starts with

OK I have a form myForm with a user control on it called myControl. I have a variety of control values on myControl which I load from the registry in the constuctor using getSetting....

so i guess you have placed the usercontrol on a form..if so the form myForm will have a closing event
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:mcintyre321
ID: 12285358
yesss.... but I don't want to have to write a bit of code in every form i use the control in telling it to kick off a dispose method in one of its . It should all be held within the usercontrol, which I can just place on the form.

I don't know why all the filled out textboxes reset to "" by the time dispose and finalize get run. I would have thought they would be intact up til one of them...
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12285392
Well then i don't think there's much option left

You will have to have a public method in the UserControl and call it on Form Closing

UserControl has Dispose function also and you can write the SaveAllSetting call there too but remeber to call Mybase.Dispose and also you'll need to call dispose explicitly from the Form on Form Closing

0
 

Author Comment

by:mcintyre321
ID: 12285565
that sucks. So much for abstraction. The dispose is useless as it seems to have removed the values from the sub controls by then.

I'll leave this Q open for a bit and then give you the points if no-one comes up with anything. I didn't want the form to have anything to do with it, but if thats how it is, thats how it is. ta
0
 

Author Comment

by:mcintyre321
ID: 12285569
sorry i sound really bitter!
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 12287254
Have you tried using the HandleDestroyed Event?

According to the remarks you should be able to query your control from within it:

     "During the HandleDestroyed event, the control is still a valid Windows control and the Handle can be recreated by calling the RecreateHandle method."

~IM
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now