Event for PgUp and PgDn on Form

E

Ed Bitzer

Would like to use PgUp and PgDn from a Form event. Have successfully been
able to use the Enter key as an event unique event from a textbox using the
boxes KeyChar event and e.KeyChar = Microsoft.VisualBasic.ChrW(13) but
search as I may through Help I have not been able to find the keycodes for
PgUp or PgDn or confirm which key event is appropriate. Trial and error is
getting me no where<g>.

Ed
 
C

Crouchie1998

Add a textBox & then add this code:

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown

If e.KeyCode = Keys.PageDown Then
MessageBox.Show(e.KeyValue)
End If

If e.KeyCode = Keys.PageUp Then
MessageBox.Show(e.KeyValue)
End If

End Sub

PageUp = 33
PageDown = 34

Crouchie1998
BA (HONS) MCP MCSE
 
E

Ed Bitzer

Crouchie, Works as advertised for a textbox but I was looking for a Form
event. I have several textboxes on my form and need the key event to do
some work that reloads all the boxes. If I place the example code under the
KeyDown event for the Form nothing happens. Suspect that is something to do
with the focus which remains in the textbox and the Form event is never
fired.

Ed
 
H

Herfried K. Wagner [MVP]

Ed,

Ed Bitzer said:
Crouchie, Works as advertised for a textbox but I was looking for a Form
event. I have several textboxes on my form and need the key event to do
some work that reloads all the boxes. If I place the example code under
the KeyDown event for the Form nothing happens. Suspect that is something
to do with the focus which remains in the textbox and the Form event is
never fired.

Make sure the form's 'KeyPreview' property is set to 'True'.
 
E

Ed Bitzer

Hefried,

That is what I was missing - and once you clued me in I admit I now see in
the Help files. I missed four times before. Still have not found the ident
of all the various special keys but trial with a message box will locate
their number, but would be nice to have their names (although this was to
obvious PgDn an PgUp - not even vbPgUp.
 
E

Ed Bitzer

Hefried, Found the listing of key codes under key code constants - gives
the old VB code and the new Net codes. Of course can not explain why I did
not find before.

Ed

Ed Bitzer said:
Hefried,

That is what I was missing - and once you clued me in I admit I now see in
the Help files. I missed four times before. Still have not found the
ident of all the various special keys but trial with a message box will
locate their number, but would be nice to have their names (although this
was to obvious PgDn an PgUp - not even vbPgUp.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top