ユーザーからユーザー名とパスワードを取得するためのフォームを作成していますが、機能しません。基本的に、ユーザー名とパスワードを入力するときに「キャンセル」を押すかウィンドウを閉じるとデータがプルされますが、「OK」を押すとクラッシュします。これは簡単な修正だと思いますが、Googleで似たようなものを見つけることができないようです(これは、より良い方法があることを示唆しています...しかし、vb.netは初めてです、ハハ)。
フォームは次のとおりです(辞書にユーザー名/パスワードを返すパブリック関数にラップされています)。
Public Function displayLoginForm() As Dictionary(Of String, String)
Dim loginForm As New Form()
Dim usernameLabel As New Label()
Dim username As New TextBox()
Dim passwordLabel As New Label()
Dim password As New TextBox()
Dim okButton As New Button()
Dim cancelButton As New Button()
usernameLabel.Text = "Username:"
usernameLabel.Location = New Point(10, 10)
usernameLabel.Width = 70
username.Height = 20
username.Width = 300
username.Location = New Point(80, 10)
passwordLabel.Text = "Password:"
passwordLabel.Location = New Point(10, 40)
passwordLabel.Width = 70
password.Height = 20
password.Width = 300
password.Location = New Point(80, 40)
okButton.Text = "Ok"
okButton.Location = New Point(220, 70)
cancelButton.Text = "Cancel"
cancelButton.Location = New Point(okButton.Left + okButton.Width + 10, okButton.Top)
loginForm.Text = "Login Form"
loginForm.Height = 130
loginForm.Width = 400
loginForm.FormBorderStyle = FormBorderStyle.FixedDialog
loginForm.MaximizeBox = False
loginForm.MinimizeBox = False
loginForm.AcceptButton = okButton
loginForm.CancelButton = cancelButton
loginForm.StartPosition = FormStartPosition.CenterScreen
loginForm.Controls.Add(usernameLabel)
loginForm.Controls.Add(username)
loginForm.Controls.Add(passwordLabel)
loginForm.Controls.Add(password)
loginForm.Controls.Add(okButton)
loginForm.Controls.Add(cancelButton)
loginForm.ShowDialog()
Dim Result As New Dictionary(Of String, String)
Result.Add("username", username.Text)
Result.Add("password", password.Text)
Return Result
End Function