Class InputForm
Inherits Form
Dim bok As Button
Dim bcancel As Button
Dim entry As TextBox
Dim result As String
Public Sub New(ByVal Prompt As String, Optional ByVal Title As String = "", Optional ByVal DefaultResponse As String = "", Optional ByVal XPos As Integer = -1, Optional ByVal YPos As Integer = -1)
SuspendLayout()
Text = Title
ClientSize = New Size(400, 120)
bok = New Button()
bok.Text = "Ok"
bcancel = New Button()
bcancel.Text = "Cancel"
entry = New TextBox()
entry.Text = DefaultResponse
result = DefaultResponse
AddHandler bok.Click, AddressOf ok_Click
AddHandler bcancel.Click, AddressOf cancel_Click
bok.Location = New Point(ClientSize.Width - bok.ClientSize.Width - 8, 8)
bcancel.Location = New Point(bok.Location.X, 8 + bok.ClientSize.Height + 8)
entry.Location = New Point(8, 80)
entry.ClientSize = New Size(ClientSize.Width - 28, entry.ClientSize.Height)
Controls.Add(bok)
Controls.Add(bcancel)
Controls.Add(entry)
ResumeLayout(False)
End Sub
Public Function Run() As String
If Me.ShowDialog = Windows.Forms.DialogResult.OK Then
Return result
Else
Return String.Empty
End If
End Function
Private Sub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
result = entry.Text
Me.DialogResult = Windows.Forms.DialogResult.OK
End Sub
Private Sub cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.DialogResult = Windows.Forms.DialogResult.Cancel
End Sub
End Class
Public Function InputBox(ByVal Prompt As String, Optional ByVal Title As String = "", Optional ByVal DefaultResponse As String = "", Optional ByVal XPos As Integer = -1, Optional ByVal YPos As Integer = -1) As String
#If TARGET_JVM = False Then
Dim f As InputForm
f = New InputForm(Prompt, Title, DefaultResponse, XPos, YPos)
Return f.Run()
#Else
Throw New NotImplementedException
#End If
End Function