JaedenRuiner
Well-known member
- Joined
- Aug 13, 2007
- Messages
- 340
- Programming Experience
- 10+
This is odd, because well it is sort of a hack, so I'll try to explain.
On other posts I mention trying to add settings to the My.Settings object to dynamically at run-time, and still have them saved to the user.config file along with the static settings created in the designer. This can be done, but it takes a little effort.
First, each property that is going to be added to the "user.config" file must be create with the correct SettingsProvider, and flagged with the User Scope Attribute. So when the program is loaded, the Settings property initially begins with the Static settings (from the designer) but when you add the dynamic settings to the Settings Object, it automatically re-examines the provider and loads those values as well.
So, for example there are Static Settings:
Idea: I have 6 basic layouts for my AdminForm, all pertaining to SplitContainer Panels being Collapsed or visible, and Splitter Distances being preset to a user configured layout. There are simply too many to really make it worth my time to waste the hour+ to manually configure all of these settings in the Settings Designer, so using this dynamic method I don't have to ever again worry about the Settings creation for form layouts.
However, the problem is that AdminForm is not my main form, it is secondary to MainForm the application's main form, which loads the AdminForm. So, as the problem of hacking the my.Settings object in such a manner arises, if I do not Load the AdminForm, the Settings Properties are never created for it, and thus when I exit the application the new user.config file overwriting the loaded one does not contain any of the dynamic settings properties. Obviously, I must create the settings properties upon application start up, but that requires the Admin Form to be "Loaded".
That's where i'm running into a glitch. the Load event seems to be called when the Show() method is called for the first time, or each time the ShowDialog() method is called. Since this is not a modal dialog, I use Show() so the user can flip back and forth between the two forms without issue. However, the AdminForm is not always necessary, so I need a way to "create" the layout into the settings property when the mainform is loaded.
That didn't work, as the error came back saying I could only set that property to nothing. it appears that the AdminForm property is already set to a "valid" instance of the AdminForm, so I tried to call the Load() event method from MainForm.Load, but when I Show()'ed the AdminForm for the first time, it called the AdminForm.Load() event again.
Additionally, I noticed that many of my forms which are truly only best used on the fly:
The Application still creates an instance of these forms in memory that are never used. So, what I'm looking to find out is:
I think this is clear enough, but i can provide more indepth detail if necessary. Primarily if I can turn off the "form Autocreate" that would be enough.
Thanks
On other posts I mention trying to add settings to the My.Settings object to dynamically at run-time, and still have them saved to the user.config file along with the static settings created in the designer. This can be done, but it takes a little effort.
First, each property that is going to be added to the "user.config" file must be create with the correct SettingsProvider, and flagged with the User Scope Attribute. So when the program is loaded, the Settings property initially begins with the Static settings (from the designer) but when you add the dynamic settings to the Settings Object, it automatically re-examines the provider and loads those values as well.
So, for example there are Static Settings:
- Form.Location
- Form.Size
Idea: I have 6 basic layouts for my AdminForm, all pertaining to SplitContainer Panels being Collapsed or visible, and Splitter Distances being preset to a user configured layout. There are simply too many to really make it worth my time to waste the hour+ to manually configure all of these settings in the Settings Designer, so using this dynamic method I don't have to ever again worry about the Settings creation for form layouts.
However, the problem is that AdminForm is not my main form, it is secondary to MainForm the application's main form, which loads the AdminForm. So, as the problem of hacking the my.Settings object in such a manner arises, if I do not Load the AdminForm, the Settings Properties are never created for it, and thus when I exit the application the new user.config file overwriting the loaded one does not contain any of the dynamic settings properties. Obviously, I must create the settings properties upon application start up, but that requires the Admin Form to be "Loaded".
That's where i'm running into a glitch. the Load event seems to be called when the Show() method is called for the first time, or each time the ShowDialog() method is called. Since this is not a modal dialog, I use Show() so the user can flip back and forth between the two forms without issue. However, the AdminForm is not always necessary, so I need a way to "create" the layout into the settings property when the mainform is loaded.
VB.NET:
private Sub Main_Load(<params>) handles Me.Load
My.Forms.AdminForm = New AdminForm()
end sub
Additionally, I noticed that many of my forms which are truly only best used on the fly:
VB.NET:
public Sub MyDoSomething()
dim frm as new MyForm1()
frm.Property = Value
if frm.ShowDialog() <> DialogResult.Cancel then
end if
frm.close()
frm.dispose()
end sub
- Is there an application setting or program option that allows me to determine what forms are created initially on App Startup and Which forms aren't, basically allowing the My.Forms property to contain a bunch of "Nothing"s until I decide a form should be instantiated.
- Upon Startup, are all the Forms listed under the My.Forms.<FormName> properties automatically created via their Default Contructor already, and thus could I put my layout creation and settings manipulation in the constructor after the "InitializeComponents()" line?
I think this is clear enough, but i can provide more indepth detail if necessary. Primarily if I can turn off the "form Autocreate" that would be enough.
Thanks