TehSquareGuy
TehSquareGuy

Reputation: 33

How to Load If Statement After Form Loads

I want to know how I can make an If statement run right after my Form3 loads. I've been searching the web for almost an hour now and I can't seem to find any information on how to do it.

If you need specifics on what I'm trying to do, it's an If statement for a conditional PictureBox1 image load. The Public variable is initially set in Form2,

Public Class Form2

    Public specialist As String = "None"

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles  Button2.Click
        specialist = "Battery: War Machine"
        My.Forms.Form3.Show()
        Close()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles  Button3.Click
        specialist = "Battery: Kinetic Armor"
        My.Forms.Form3.Show()
        Close()
    End Sub
End Class

Then in Form3, I want to know how to run this if statement.

Public Class Form3
    Public specialist As String = (Form2.specialist)
    If specialist = "Battery: War Machine" Then
        PictureBox1.Image = My.Resources.BatteryLobby3
    Else
        PictureBox1.Image = My.Resources.Nope
    End If
End Class

But I want it to run right when Form3 starts, without having to click a button or anything.

Upvotes: 1

Views: 613

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54417

The Load event of a form is raised immediately before the form is displayed for the first time. The Shown event is raised immediately after the form is displayed for the first time.

Upvotes: 1

Related Questions