简体   繁体   中英

C# Windows Application - User Settings on InitializeComponent()

I am trying to use persisted user settings (.settings) within the rendering of the components ie InitializeComponent() - Visual Studios WinForms designer support function, designer.cs.

For example, if an option was unchecked last sessions, it should remain unchecked this time.

It is working fine if I first render the components of the form ie running InitializeComponent() , and then within the initializer class of the program set the properties using the user settings.
But this is not very tidy and would rather it all be rendered together within the same function.

Is there any reason this is not working? Maybe I am missing some kind of assembly reference that is required for it to work?

Please note, my InitializeComponent() function is in a separate namespace

You do not want touch InitializeComponent() . This code is all generated by the designer.

If you want to keep things tidy, I would suggest setting any user settings within the form_Load event. This is called directly after the form's constructor.

Found the issue.

Was a problem in using both .Checked and .CheckState in the rendering. Seems it only likes one being used.

Now works fine and can correctly use the user local settings to populate the fields.

Nice and clean now. Thanks all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM