Hi @Štefan Mihael Rihar ,
Try the following code to see if it meets your expectations?
The strange class actually defines the form that pops up after you press the button in Form1.
Strange.vb
Public Class Strange
Inherits Form
Public WithEvents Button1 As Button
Private userNameValue As String
Public Property UserName() As String
Get
' Gets the property value.
Return userNameValue
End Get
Set(ByVal Value As String)
' Sets the property value.
userNameValue = Value
End Set
End Property
Public Sub Capitalize()
' Capitalize the value of the property.
userNameValue = UCase(userNameValue)
End Sub
Public Sub New(ByVal UserName As String)
' Set the property value.
Me.UserName = UserName
Button1 = New Button With {
.Size = New Size(40, 40),
.Location = New Point(30, 30),
.Text = "Click Me"
}
Me.Controls.Add(Button1)
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
' Create an instance of the class.
Dim user As New Strange("Moore, Bobby")
' Capitalize the value of the property.
user.Capitalize()
' Display the value of the property.
MsgBox("The original UserName is: " & user.UserName)
' Change the value of the property.
user.UserName = "Worden, Joe"
' Redisplay the value of the property.
MsgBox("The new UserName is: " & user.UserName)
End Sub
End Class
Form1.vb
Public Class Form1
Public WithEvents Button1 As Button
Public Second_Class As New Strange
Sub New()
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
Buuton_One_Procedure_Or_Method()
End Sub
Sub Buuton_One_Procedure_Or_Method()
Button1 = New Button()
Button1.Size = New Size(40, 40)
Button1.Location = New Point(30, 30)
Button1.Text = "Click me"
Me.Controls.Add(Button1)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim MyName As String = "name"
Dim MyForm As New Strange(MyName) 'This line is used to create a Strange class object
MyForm.ShowDialog()
End Sub
End Class