I was working with VB6. Now I am trying to study VB.NET. In vb6 There is Cancel property for command button
eg. If we make the cancel property of exit command button 'True',then if we press Esc key ,we can exit from that form even without clicking the exit button.
On studying the properties of buton in VB.NET I couldn't see the cancel property.Am I right ? or Is there any similar property for the buttons..

Any body please advise me..

Recommended Answers

All 2 Replies

The form has a CancelButton property, so you could do something like:
MyForm.CancelButton = MyCancelButton

You can create a keydown event for the exit button, and insert the code below, but in order to press on the escape button and exit the form, the exit button needs to be in focus.

Private Sub ButtonExit_KeyDown(sender As Object, e As KeyEventArgs) Handles ButtonExit.KeyDown
    Select Case e.KeyCode
       Case Keys.Escape
    End Select
 End Sub

You can bring back the focus to the exit button either when you click on the form:

Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
End Sub

or when you hover with the mouse over the form:

Private Sub Form1_MouseHover(sender As Object, e As EventArgs) Handles Me.MouseHover
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.