|
-
Jul 10th, 2021, 05:24 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to save settings for UserControl(s)?
Hi all. 
Saving parameters for keeping data after shutting down is possible through Project>Settings.
I already used several items to save (fonts, checkboxes booleans, strings, etc.)
Code overview would look like this:
Code:
Private my_digit1 As Boolean
Public Sub New()
InitializeComponent()
InitializeSettings()
End Sub
Private Sub InitializeSettings()
my_digit1 = My.Settings.digitm1
End Sub
*Some graphical settings were also done.
- (ApplicationSettings)
(PropertyBindings)
Value: digitm1
The problem is, how can I save some UserControl array, control values in settings and recall them in every opening?
-
Jul 10th, 2021, 05:49 AM
#2
Re: How to save settings for UserControl(s)?
Are you saying, without actually saying, that you will have an unknown number of instances of this user control type and you want to save the configuration of each one? If so then you won't be able to use binding. You could still use settings though, if you were to use a single setting to store some XML that contained the configuration for all the controls. You'd have to write code to save the property values from the controls to the XML and to load it again. It's basically a manual process, just as you'd expect it to be, with the decision to be made being where to store the data.
-
Jul 10th, 2021, 06:29 AM
#3
Thread Starter
Hyperactive Member
Re: How to save settings for UserControl(s)?
I'm OK with manual ways, but I'm not sure how to do it.
There are 24 User controls, each containing 2 CheckBoxes and 2 NumericUpDowns, 96 items to save overall.
-
Jul 10th, 2021, 08:18 AM
#4
Re: How to save settings for UserControl(s)?
So you do know exactly what there is at design time, so you can just bind the properties like you would for any other control, so do that. You obviously need to add the properties in order to be able to bind them. You just add a pass-through property to the user control for each child control property to need to access, e.g.
vb.net Code:
Public Property CheckBox1Checked As Boolean
Get
Return CheckBox1.Checked
End Get
Set
CheckBox1.Checked = value
End Set
End Property
It's a property like any other, so you bind it like any other.
-
Jul 12th, 2021, 07:36 AM
#5
Thread Starter
Hyperactive Member
Re: How to save settings for UserControl(s)?
Thanks, It works.
There is a saying: If you are doing something repetitious in programming, you're doing it wrong. I'm copy-pasting a satisfactorily working code, for 96 items, 3 time (calling, saving, opening) I kinda feel like a bit stoopid. But things are working properly now...
-
Jul 12th, 2021, 07:41 AM
#6
Re: How to save settings for UserControl(s)?
 Originally Posted by pourkascheff
Thanks, It works.
There is a saying: If you are doing something repetitious in programming, you're doing it wrong. I'm copy-pasting a satisfactorily working code, for 96 items, 3 time (calling, saving, opening) I kinda feel like a bit stoopid. But things are working properly now...
Um, that's not what I said to do so it would appear that that saying is rather apt.
-
Jul 12th, 2021, 03:54 PM
#7
Re: How to save settings for UserControl(s)?
What you might consider is making up a class that contains all the settings, either per control or for the whole thing. It sounds like you aren't saving all that many properties for the controls, so one per control might be the most extensible solution. You can then make the class XML serializable such that the serialization/deserialization is simpler, or you could even go to binary serialization which has advantages (smaller, MUCH harder to read and change outside of the program) and disadvantages (MUCH harder to read and change outside of the program...which has other implications).
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|