Is there the possibility to call the click method of a button when Enter is pressed? If this is of any help, textboxes in VWG had an event called Textbox.EnterKeyDown, in which one could call the Button.PerformClick() method.
Thank you, Frank. I thought this would be the problem, since I had observed some strange behaviour in the designer. To visualize panels in base class controls I had set their background colours and after saving or drag-n-drop or close/open the inheriting control, colours changed, i.e. higher z-index panels surfaced to the top. Hope you understand what I mean. I haven’t managed to replicate the behaviour consistently though. If I do, I ‘ll send you an example.
Thanks again, and have a nice weekend (hope you’re planning to take some time off! )
I had a quick look. It seems that one of the inner panel “swallowed” the textboxes and buttons changing the hierarchy. It may have happened when dragging on the designer. Controls are registered in the browser using the parent/child hierarchy.
So now you should either:
Now, although your sample works, when I put it in my project it doesn’t. My user control inherits from another Usercontrol which in turn inherits from a base usercontrol. I have attached your sample project modified so that it doesn’t work! Have a look.
The example works very nicely and the explanation “all events bubble unless stopped …” shows the potential of this approach.
Hi Frank, thanks for your code, I’ll give it a go.
You are right about tot creating an event specifically for a single key. To be honest, what I thought it would be easier, was to include an AcceptButton property for the UserControl class, as you have for the Form.
I have picked up your scenario of a UserControl and created a sample that illustratres the handling of Enter and Escape keys.
This is a lot better than singling out a specific key and having to handle it on each textbox. It allows you to process the keys on the client at a higher level and to fire any event on any other component.
Hope that helps.
Hi Frank, thank you for your answer.
Now something more difficult: What if I do not have a form, but a UserControl? In my case, I have encapsulated the authentication process in a “Login” UserControl, with a Username and Password textboxes, a Submit button and a “Change Password” link which opens a popup to allow the user to change password. The Usercontrol communicates with its contaner form by raising an event “LoginClicked”, the textboxes and submit button are private and not visible by the container form. I saw that the UserControl does not have an AcceptButton property. Does this mean I will have to make the submit button public and set the Form.AcceptButton = UserControl.LoginButton ??
Please login first to submit.