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
-
The page directive lets you define one or more of the following case-sensitive attributes: * import="package.class" or import=...
-
SQL Replication term describes a group of technologies allowing information distribution and mirroring between different databases. SQL repl...
-
SQL Server Express is a free, easy to use, redistributable version of SQL Server 2005 designed for building simple data-driven applications....
-
The SQL SELECT INTO statement is used to select data from a SQL database table and to insert it to a different table at the same time. The g...
-
MS SQL Server or simply SQL Server is RDBMS developed by Microsoft Corp. SQL Server uses a dialect of SQL called Transact-SQL (T-SQL). The S...
-
SQL Management Studio comes in two flavours: 1. SQL Management Studio This edition comes with all versions of SQL Server 2005 except SQL Ser...
-
IT professionals and students from all over the world have many options for SQL training nowadays. They can learn SQL by going to instructo...
-
The SQL AVG aggregate function selects the average value for certain table column. Have a look at the SQL AVG syntax: SELECT AVG(Column1) FR...
-
Learning about Parameters Parameters are variables that being passed to a Sub. Look at the first line of the Command Button's Click even...
-
A JSP expression is used to insert Java values directly into the output. It has the following form: The Java expression is evaluated, conver...
No comments:
Post a Comment