Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. trap arrow keys in usercontrol

trap arrow keys in usercontrol

Scheduled Pinned Locked Moved C#
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hello everybody, Does anyone know how to trap the arrow keys in a class derived from usercontrol? I noticed that the arrows keys don't fire a keyup, keydown or keypress event, instead they move the focus to other controls on the form like the Tab key does. I want the control itself to be able to process the arrows keys without having to add code to the form that is it in. Thanks in advance Paul

    J 1 Reply Last reply
    0
    • L Lost User

      Hello everybody, Does anyone know how to trap the arrow keys in a class derived from usercontrol? I noticed that the arrows keys don't fire a keyup, keydown or keypress event, instead they move the focus to other controls on the form like the Tab key does. I want the control itself to be able to process the arrows keys without having to add code to the form that is it in. Thanks in advance Paul

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Look at the IsInputKey protected method on the usercontrol.

      protected override bool IsInputKey(Keys keyData)
      {
      // Arrow keys are not considered input keys for
      this control,
      // need to override this method to make them so
      if (keyData == Keys.Left ||
      keyData == Keys.Right ||
      keyData == Keys.Up ||
      keyData == Keys.Down)
      return true;
      else
      return base.IsInputKey(keyData);
      }

      Then I think the OnKey* events will fire for it, the docs aren't too clear on that aspect. Your control will have to have the UIPermission.AllWindows security permission to run that code however. HTH, James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups