The Form's KeyPreview Property
To understand this property,
lets look on the following example:
Start new project, and add 1 Command Button
(named Command1) to your form.
verify that the Form's KeyPreview property is set to "False".
Add the following code to your program:
Private Sub Command1_KeyPress(KeyAscii As Integer)
Print "Button Pressed"
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Print "Form Pressed"
End Sub
The code above will print "Button Pressed" on
the form when the Command Button's KeyPress event
will be executed, and print "Form Pressed" when the
Form's KeyPress event will be executed.
Run the program and press any key on the keyboard.
"Button Pressed" is appearing on the form, but
"Form Pressed" isn't appearing.
The Form's KeyPress event hasn't been executed.
When the KeyPreview property is "False",
if any control is found on the form (the command button in this case),
It will get all the Key events (KeyPress, KeyDown and KeyUp)
instead of the form.
To allow the Form's Key events be executed,
set the KeyPreview property to "True".
Lets try it. Set the KeyPreview
property to "True", run the program again
and press any key.
The Form's KeyPress event has been executed,
in addition to the Button's KeyPress event that
been executed too.
Notice That the form's KeyPress event executed
before the Button's event.
Popular Posts
-
When an HTTP client such as web browser sends a request to a wen server, along with the request it also sends some HTTP variables like Remot...
-
Console Applications Console Applications are command-line oriented applications that allow us to read characters from the console, write ch...
-
JSP pages are high level extension of servlet and it enable the developers to embed java code in html pages. JSP files are finally compiled ...
-
Getting Started (Continue) Look at the form with the title bar Form1. This is how your program will look like. Everything you will place on ...
-
Adding Controls to the Form There are many controls you can use with your program: Buttons, Text Boxes, Pictures, Scroll Bars and more. You ...
-
Using functions we can structure our programs in a more modular way, accessing all the potential that structured programming can offer to us...
-
4.5 Using FCL Documentation for Types Using the SDK documentation for a given type will likely be a daily or even hourly event when ...
-
Servlets Life Cycle have the following Components: * Handled by the servlets container. * Create and initialize the servlets. ...
-
We have already learned how groups of sequential data can be used in C++. But this is somewhat restrictive, since in many occasions what we ...
-
Learning about Parameters Parameters are variables that being passed to a Sub. Look at the first line of the Command Button's Click even...
No comments:
Post a Comment