KeyPreview does not intercept keys in Combo Box

V

Vadim Rapp

Hi:

On my form, I have textbox and combo box. Form's KeyPreview = True. It does
work for the textbox, but not for the combo. I.e.

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
me.Text = e.KeyChar
End Sub

does intercept keys pressed in the textbox, but not in the combobox. Is
there any explanation for this?

thanks,

Vadim
 
H

Herfried K. Wagner [MVP]

* "Vadim Rapp said:
On my form, I have textbox and combo box. Form's KeyPreview = True. It does
work for the textbox, but not for the combo. I.e.

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
me.Text = e.KeyChar
End Sub

does intercept keys pressed in the textbox, but not in the combobox. Is
there any explanation for this?

Which version of .NET do you use? AFAIK this is a bug in .NET 1.0.
 
V

Vadim Rapp

HKW> Which version of .NET do you use? AFAIK this is
HKW> a bug in .NET 1.0.

1.1.4322

Vadim
 
E

EricJ

if you use it on the combo iself it wil work (i use that a lot)
Private Sub cboLijn_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles cboLijn.KeyPress

if you want the form keypress events i suggest you use this (from the 'enter
key' thread tnx to the ppl that replied there :)

Turn "KeyPreview ON" for the form before your try this code:


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

If e.KeyCode = Keys.Enter Then
If Not ActiveControl Is Nothing Then
SendKeys.Send("{TAB}")
End If
End If

End Sub
 

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