I have a project with more than one form and I move between them with a button click that hides the current form and shows the one I want. But what is I want to perform some procedure each time the form is shown? I tried this code on my Form2:

Private Sub Form2_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        MsgBox(testString)

    End Sub

... to put a variable into MsgBox and, when I run the program, it works the first time the form is shown, but not when I go back to it from another form. Is there some other event handler I should be using?

i dont get you......
like in Form1 you got like Button1 to go to Form2 Button 2 to go to Form3

in Form2 u got a button1 to go back to form1 and button 2 to go to Form3

in Form3 u got a button1 to go back to form2 and button 2 to go back to
form 1?

or something like that? cuz i dont get u

OP wants to run a code whenever a Form2 is shown.

Private Sub Form2_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        If Visible = True Then
            MsgBox(testString)
        End If
    End Sub

i dont get you......
like in Form1 you got like Button1 to go to Form2 Button 2 to go to Form3

in Form2 u got a button1 to go back to form1 and button 2 to go to Form3

in Form3 u got a button1 to go back to form2 and button 2 to go back to
form 1?

or something like that? cuz i dont get u

The reason for the buttons and forms is only practice to see how it works. The programs I will be writing require more than one form.

Thanks to Yorro. I didn't know how visibleChanged worked.

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.