Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Latly it would seem as though I'm don't abnegate from anything... except women. :( :)
  • *Experts*
Posted

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

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted
I'm not talking about a form, its a usercontrol, and it dosn't seem to have a KeyPreview property.
Latly it would seem as though I'm don't abnegate from anything... except women. :( :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...