VB.NET Inputbox - How to identify when the Cancel Button is pressed?

前端 未结 12 1732
灰色年华
灰色年华 2021-01-03 22:26

I have a simple windows application that pops up an input box for users to enter in a date to do searches.

How do I identify if the user clicked on the Cancel butt

12条回答
  •  春和景丽
    2021-01-03 23:11

    Here is what I did and it worked perfectly for what I was looking to do:

    Dim StatusDate As String
     StatusDate = InputBox("What status date do you want to pull?", "Enter Status Date", " ")
    
            If StatusDate = " " Then
                MessageBox.Show("You must enter a Status date to continue.")
                Exit Sub
            ElseIf StatusDate = "" Then
                Exit Sub
            End If
    

    This key was to set the default value of the input box to be an actual space, so a user pressing just the OK button would return a value of " " while pressing cancel returns ""

    From a usability standpoint, the defaulted value in the input box starts highlighted and is cleared when a user types so the experience is no different than if the box had no value.

提交回复
热议问题