Guys I just want to ask why my KeyPress event is apparently not working. What I want is that when I press the letter m, the selectedindex property of my listboxes would change.
Here is the code;

Select Case Asc(e.KeyChar)
Case 13
Try
tray.ListBox1.SelectedIndex = tray.ListBox1.SelectedIndex + 1
tray.ListBox2.SelectedIndex = tray.ListBox1.SelectedIndex
PictureBox1.ImageLocation = tray.ListBox2.SelectedItem
e.Handled = True
Catch ex As Exception
ToolStripLabel1.Text = ex.Message
End Try
Case 26
Try
tray.ListBox1.SelectedIndex = tray.ListBox1.SelectedIndex - 1
tray.ListBox2.SelectedIndex = tray.ListBox1.SelectedIndex
PictureBox1.ImageLocation = tray.ListBox2.SelectedItem
e.Handled = True
Catch ex As Exception
ToolStripLabel1.Text = ex.Message
End Try
End Select

I also want to know what the "e.handled = true" is statement for. I set the KeyPreview property of my form to false and true but it's not working as well.
the KeyPress event should be triggered regardless of the control within the form that is in focus.

Thanks

Recommended Answers

hello !
if u just want to use keypress event then use this code

if e.keychar= chr(keys.m) then 
'here place your code
endif

hope this will helps you
Regards

M.Waqas Aslam

Jump to Post

All 2 Replies

hello !
if u just want to use keypress event then use this code

if e.keychar= chr(keys.m) then 
'here place your code
endif

hope this will helps you
Regards

M.Waqas Aslam

Just copy and paste this code to KEY UP and KEY DOWN event as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.