GMMorris Posted April 10, 2004 Posted April 10, 2004 Hi, I want to capture an event where a user presses CTRL at design time while my control is in selection - is this possible? I tried using: protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e) { MessageBox.Show(e.Control.ToString()); } But it didn't work Quote Latly it would seem as though I'm don't abnegate from anything... except women. :( :)
*Experts* DiverDan Posted April 10, 2004 *Experts* Posted April 10, 2004 Use the KeyPress or KeyDown events, making sure that the form's KeyPreview properity is set to True. Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress If Asc(e.KeyChar) = Keys.Control Then 'do something here e.Handled = True End If End Sub or Public Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.N And e.Modifiers = Keys.Control Then 'do something here End Sub Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
GMMorris Posted April 12, 2004 Author Posted April 12, 2004 I'm not talking about a form, its a usercontrol, and it dosn't seem to have a KeyPreview property. Quote Latly it would seem as though I'm don't abnegate from anything... except women. :( :)
*Experts* DiverDan Posted April 12, 2004 *Experts* Posted April 12, 2004 Opps...Read your post a bit too quickly. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.