?
Solved

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

Posted on 2004-10-12
11
Medium Priority
?
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 86

Accepted Solution

by:
Mike Tomlinson earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 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