Solved

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

Posted on 2004-10-12
11
207 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 

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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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