フォームから派生したクラスがあり、ユーザー名とパスワードのテキストボックスと [OK] ボタンがあります。InputBox のように動作させたいので、次のように使用できます。
Dim Username As String = ""
Dim Password As String = ""
Dim authorization As New Authorization(Username, Password)
authorization.ShowDialog()
'The user will click OK and I will expect the Username and Password to change based on the user input
MsgBox(Username & " " & Password)
認可クラス:
Public Class Authorization
Dim RefUsername As String
Dim RefPassword As String
Public Sub New(ByRef Username As String, ByRef Password As String)
InitializeComponent()
RefUsername = Username 'I'm trying to pass reference instead of value
RefPassword = Password 'I'm trying to pass reference instead of value
End Sub
Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AuthorizeButton.Click
RefUsername = Username.Text 'I'm trying to change value of variable outside the class
RefPassword = Password.Text 'I'm trying to change value of variable outside the class
Me.Close()
End Sub
End Class
要するに、ユーザーが [OK] をクリックしたときにクラス外の変数の値を変更したいのですが、どうすればそれを達成できますか?