Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15524

Use Form2 To Change Form1 Control

$
0
0
form1 has a label on it.
form2 has a button on it.

But I can't work out how to change the label's text via the button.
The code below doesn't work. It just says frm1 is not declared.
Code:

Public Class Form2

        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        dim frm1 As New Form1
        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        frm1.Label1.Text = "Text goes here"
        End Sub

End Class

I looked on the net and it may have something to do with the scope of the variable.

But when I did this...

Public Class Form2
Public Shared frm1 As New form1

It still doesn't work. So what code am I missing? Thanks.

Viewing all articles
Browse latest Browse all 15524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>