vb.net中class如何控制标签

How to control the label by class in vb.net

我无法使用 class 更改标签颜色。 enter image description here

Public Sub change_color()
    Form1.Label1.BackColor = Color.Red
End Sub

首先去你的class

Public Class My_class 

      Public Say As String  'if you make it Dim you can't get the value by sure to make it Public

      Public Function Do_somthing(ByVal Form As Form1)  ' Function
           Say = "Hi"
           Form.Label1.Text = "Boo!"
           Return True
      End Function

End Class

第二次转到您的表单

Public Class Form1
      Dim MyClass As New My_Class() ' Here to call ur class to make it easy

      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
          ' Here You Call the Function 
           MyClass.Do_somthing(Me) 
           ' Why (Me) because you want 'Your Class' get Full Access to Form Class
      End Sub

      Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
          ' Here You Call String value
           Label2.Text = MyClass.Say.ToString()
      End Sub


End Class