Windows Develop Bookmark and Share   
 index > Windows Forms General > Load setting without calling code?
 

Load setting without calling code?

Dont know how to really explain this, maybe its simple but i cant find a way. Anyway, this is my code:

Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Settings.IsAuthenticated Then

        End If
End Sub

Not really doing anything in the above code, but the below one gets executed instead.

Private Sub MySettings_SettingsLoaded(ByVal sender As Object, ByVal e As System.Configuration.SettingsLoadedEventArgs) Handles Me.SettingsLoaded
     If My.Settings.IsAuthenticated Then
         Main.LblUser.Caption = "Logged in as: " & My.Settings.Username
     Else
         Main.LblUser.Caption = "Guest"
     End If
End Sub



Is there a way to call the above code in the Load event without using the IF ENDIF statements, it basically just needs to load a setting. When it is loaded the other code will run??

Se3ker385  Thursday, September 10, 2009 4:02 PM
Hello Se3ker,

I cannot understand the requirement clearly, so I want to clarify it with you.

Do you mean when My.Settings.IsAuthenticated is True, the form title should be changed to "Logged in as: XXX", when it is false, the title should be "Guest"? I think you don't need to handle the "SettingsLoaded" event, just put these code into Main_Load method is ok.
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Settings.IsAuthenticated Then
Main.LblUser.Caption = "Logged in as: " & My.Settings.Username
Else
Main.LblUser.Caption = "Guest"
End If
End Sub

>Is there a way to call the above code in the Load event without using the IF ENDIF statements, it basically just needs to load a setting. When it is loaded the other code will run??

What I confused was the above question. Could you please explain it clearly?

Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework!
Kira Qian  Monday, September 14, 2009 6:55 AM
The reason i put it in the Settings loaded event is i need this code to run when the setting is loaded, but i dont know a way to actually just load/call the particular setting without the IF statement.

And then the IF ENDIF is just blank, so it looks silly. So is there another way of doing this?
VB.NET to C# http://www.developerfusion.com/tools/convert/vb-to-csharp/
Se3ker385  Monday, September 14, 2009 7:00 AM
Hello Se3ker385,

The SettingsLoaded event occurs only after the initial get access of the first configuration property used, typically through the Item method. So you can just use the settings' value and don't need to care its loading process.

Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework!
Kira Qian  Monday, September 14, 2009 8:12 AM
Not really following you there, could you please explain?

Isopose i could move my code to a module level, but it seems convenient in the SettingsLoaded as it is also tied to PropertyChanged event and i can easily just call it from anywhere then. The only silly thing is i just call/execute it like so: If My.Settings.IsAuthenticated End If ;
VB.NET to C# http://www.developerfusion.com/tools/convert/vb-to-csharp/
Se3ker385  Monday, September 14, 2009 1:58 PM

You can use google to search for other answers

Custom Search

More Threads

• Advanced Tree Control Structure
• Controlling one form to another
• mdi child child communication
• Xml to Access Database
• HtmlDocument.InnerText
• Better Tab Control?
• HOW TO: retrieve a list of selected virtual items in list view in virtual mode
• RemoteDirectoyListing
• doevents c# threading sample
• SQL Server option missing from Data Source window. Anyone know how to fix this?