in form1 there is a checkbox witch when you click , it will save checked value in xml file

in splash screen its has a label1.text = "welcome "
what i want is ,when splashscreen loading up check if settings of form1.checkbox1.checked if true then
do
[splashscreen]
me.text ="your not welcome"

Private Sub SplashScreen1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Settings.form1_checkbox = Form1.Checkbox1.checked Then
            Label1.Text = "your not welcome"
        Else
            Label1.Text = "welcome"
        End If
    End Sub

Dani AI

Generated

Short answer: store a Boolean user setting and read that setting from the splash screen — do not try to read Form1.Checkbox1 from the splash, because the main form may not exist yet. was right to recommend a Boolean setting; 's question points to the root cause: the splash should read the persisted value, not the live control on another form.

Save the checkbox state when it changes (user-scoped setting, save to disk):

Private Sub Checkbox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Checkbox1.CheckedChanged
    My.Settings.form1_checkbox = Checkbox1.Checked
    My.Settings.Save()  ' or call Save once on application exit
End Sub

Ensure the setting in Project → Properties → Settings is Type = Boolean and Scope = User. Then the splash can read My.Settings.form1_checkbox directly (no Form1 references). If the project uses a custom XML file instead of My.Settings, parse it before using it in the splash; a simple example using LINQ to XML:

Dim checked As Boolean = False
Dim path As String = Path.Combine(Application.StartupPath, "settings.xml")
If File.Exists(path) Then
    Dim doc = XDocument.Load(path)
    Dim val = doc.Root.Element("Form1")?.Element("Checkbox1")?.Value
    Boolean.TryParse(val, checked)
End If
Label1.Text = If(checked, "your not welcome", "welcome")

Cautions: only user-scoped settings are writable at runtime; calling My.Settings.Save persists changes; avoid referencing other forms' controls from startup/splash code (default instances can hide timing bugs).

Recommended Answers

All 3 Replies

What is your problem?

in form1 there is a checkbox1.checked=true witch it saved in xml file so
i want in load even of splash screen . it read the checked value from form1.Checkbox1
settings if its true or not

is there a way to do it ?


i want splash screen read the checked value of form1.checkbox1 xml settings file and check if its true or not
thats all !


witch that code dose not work

If I understand right: change the type of the setting "form1_checkbox" to Boolean
change the if statement to:

Private Sub SplashScreen1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Settings.form1_checkbox = False Then
            Label1.Text = "your not welcome"
        Else
            Label1.Text = "welcome"
        End If
    End Sub

Not sure how to do xml but somewhere in the code I would add a sub with something like:

Public Sub checkxml()
dim ischkboxchecked as Boolean = false
' Parse the XML to read it and set the ischkboxchecked to the result
My.settings.form1_checkbox = ischkboxchked
end sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.