Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi friends
i write a code like

VB
Private Sub flash_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    If e.KeyCode = Keys.Escape Then
        Me.Close()
    End If
End Sub

In vb.net the code is work.But when i drag and drop the shack wave flash object control on form designing after i run the form the above code does not work.How can i rectify this problem???
Advance thanks to all.....
Posted
Updated 5-Nov-12 7:56am
v3
Comments
Sergey Alexandrovich Kryukov 5-Nov-12 13:50pm    
"Does not work" is not informative enough. What exactly the problem is? And what is "Me" here? A form? Why closing it in this strange way? If this is a modal window, it's closed by itself; you need to have CancelButton.
--SA
SPprasath 5-Nov-12 14:01pm    
Thank u....
Sergey Alexandrovich Kryukov 5-Nov-12 14:37pm    
You are welcome.
If you agree that my answer makes sense, please accept it formally (green button) -- thanks.
--SA

1 solution

This is not a good way to close a window. If you show a window as modal (via ShowDialog), you need to use CancelButton; and the form will close itself on escape:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.cancelbutton.aspx[^].

And if the form is not modal, you should never close it with Escape, as it will violated expected UI style and can cause loss of user's work, by apparent reasons.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900