Best practice for sharing variables across forms in VB.NET

后端 未结 6 1539
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-07 05:56

I need to share variables across two forms in VB.NET. One of them is the main form and the other is a child form.

I have been searching, and I have found a few metho

6条回答
  •  不要未来只要你来
    2021-01-07 06:20

    Create two forms. Add 3 radio buttons and 1 button to form1. Add a label to form2. In the code for form1 type

        Public rdb As Integer = 1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
         Form2.Show()
    If RadioButton1.Checked Then
                rdb = 1
            ElseIf RadioButton2.Checked Then
                rdb = 2
            ElseIf RadioButton3.Checked Then
                rdb = 3
            End If
    End Sub
    

    Then in form2's code

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Label1.Text = Form1.rdb
        End Sub
    

提交回复
热议问题