Default InputBox Behavior

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Here is my code:

Private Sub cmP1JoyUpLabelSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmP1JoyUpLabelSize.Click
lblP1JoyUp.Width = InputBox("Enter the Width of the label.")
lblP1JoyUp.Height = InputBox("Enter the Height of the label.")
End Sub

After the box pops up how do I allow the user to back out without entering and data. It errors out if the input field is left empty or if the cancel button is clicked.

Thank you,
John
 
dim sInput as string
sInput = InputBox("Enter the Width of the label.")
if len(sInput)>0 then
lblP1JoyUp.Width = CInt(sInput)
end if

so if the user cancels out or does not enter anything, it will not try to set the width
of the label.
there's still one problem: if sInput cannot be cast to an integer, it'll blow up. you'll
most likely have to put the CInt() into a try catch block and look for a InvalidCastException.

hope this helps..
 
Awesome!

Thank you,
John

ISK said:
dim sInput as string
sInput = InputBox("Enter the Width of the label.")
if len(sInput)>0 then
lblP1JoyUp.Width = CInt(sInput)
end if

so if the user cancels out or does not enter anything, it will not try to set the width
of the label.
there's still one problem: if sInput cannot be cast to an integer, it'll blow up. you'll
most likely have to put the CInt() into a try catch block and look for a InvalidCastException.

hope this helps..
 
Hi John,

Doing this with the inputbox is a little bit old fashion and gives no nice
results, why not your own dialogbox, see this sample I just made for it.

I hope this helps?

Cor

\\\Your Main form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim frm As New MyDialogBox("Enter Value")
If frm.ShowDialog = DialogResult.OK Then
MessageBox.Show(frm.TextBox1.Text)
End If
frm.Dispose()
End Sub
///
\\\Form2 (Rename the class name in top to MyDialogBox)
Public Class MyDialogBox
....
Public Sub New(ByVal BoxText As String)
MyBase.New()
InitializeComponent()
Me.Text = BoxText
End Sub
Private Sub frmLogin_Load(ByVal sender _
As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CancelButton = Me.Button2
End Sub
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub
///
 
Back
Top