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
-
4 Reusable Components and the FCL Up to this point I have spoken quite a bit about the goals of the .NET Framework, as well as what it ...
-
So far we’ve learnt how to select data from a database table and how to insert and update data into a database table. Now it’s time to learn...
-
package interfaceexercise; // Define an interface with three abstract methods. // Any class that implements this interface has to // impleme...
-
We will use the Customers table to illustrate the SQL LIKE clause usage: FirstName LastName Email DOB Phone John Smith John.Smith@yaho...
-
3 Visual Studio .NET This section is a short one, but I cannot go on without mentioning Visual Studio .NET. Visual Studio .NET is not ...
-
Please do this exercise at the command line instead of using NetBeans. This is to learn the concept of packaging without the help of NetBean...
-
CONTROL STRUCTURES: Three types of control structures: 1.Decision control structure : if,if else,nested if etc 2.Loop control structure ...
-
MouseMove, MouseDown and MouseUp Events Lets check out the Command Button's MouseMove, MouseDown and MouseUp events. We will do that lik...
-
Introduction: In this exercise, you will exercise the concept of comparing objects using String class as an example. Steps to follow: 1. Wri...
-
Steps to follow: 1. Modify Main.java as shown below in Code-11.2.a under personpackage directory. (You are welcome to do this work using ei...
No comments:
Post a Comment