Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to cancel a form with a text box with the Leave Event coded

How to cancel a form with a text box with the Leave Event coded

Scheduled Pinned Locked Moved Visual Basic
questiontutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SerialHobbyist
    wrote on last edited by
    #1

    My New User form has a pair of text boxes used to define new users to my app. For both I've used the 'Leave' event to validate them before the form's OK button is enabled. (I've included the code for the simpler one of the two below.) I also want a Cancel button so that the user can choose not to set up a new user. At the mo, the Cancel button just sets DialogResult.Cancel. When the user clicks on the Cancel button the first time, the Leave event is still triggered and the users gets a "You must enter a name." message box. If the user clicks Cancel again, the window closes. I realise that I could do the checks when the user clicks OK but it seems 'more OO' to validate each box. How can I avoid this message box on cancel but still check the formatting when the user moves out of the text box otherwise?

    Private Sub txtNewOppName_Leave(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles txtNewOppName.Leave

    If txtNewOppName.Text = "" Then 
    Me.NameDefined = False
    MessageBox.Show("You must enter a name.")
    Me.Select()
    Else
    Me.NameDefined = True
    End If
    
    If Me.EmailDefined And Me.NameDefined Then
    Me.btnOk.Enabled = True
    End If
    

    End Sub

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups