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
-
SQL aliases can be used with database tables and with database table columns, depending on task you are performing. SQL column aliases are u...
-
STRINGS: The way a group of integers can be stored in an integer array, similarly a group of characters can be stored in a character array. ...
-
1 Introducing the .NET Framework with C# The .NET Framework is such a comprehensive platform that it can be a little difficult to descr...
-
The SQL ORDER BY clause comes in handy when you want to sort your SQL result sets by some column(s). For example if you want to select all t...
-
Java Server Pages JavaServer Pages (JSP) technology is the Java platform technology for delivering dynamic content to web clients in a por...
-
Inheritance A key feature of OOP is reusability. It's always time saving and useful if we can reuse something that already exists rather...
-
Declaration of variables In order to use a variable in C++, we must first declare it specifying which data type we want it to be. The syntax...
-
A "service" is an application that can start automatically when the computer starts. There are two start up modes: 1. Automatic - ...
-
More About Ascii How can I know what is the Ascii value of a specific character? Use the Asc command. For example, the following line: Print...
-
Arguments passed by value and by reference. Until now, in all the functions we have seen, the arguments passed to the functions have been pa...
No comments:
Post a Comment