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. Stop Button from taking focus during a keypress or keyup event.

Stop Button from taking focus during a keypress or keyup event.

Scheduled Pinned Locked Moved C#
questionhelp
2 Posts 1 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.
  • B Offline
    B Offline
    bradsnobar
    wrote on last edited by
    #1

    I wrote a custom menu control that accepts keyboard movement. I have a form with a button on it. When I click the button I see my menu pop up below the button. The problem is that the focus shifts between the button and the custom control whenever I press an arrow key. How do I keep other controls from stealing focus away from my custom control. I don't want to disable other controls. I want to maintain focus in my custom control I've tried to set the handled and the suppressKeyPress functionality in the event but the button still grabs focus for every other keypress. Any ideas? Thanks, Brad

    B 1 Reply Last reply
    0
    • B bradsnobar

      I wrote a custom menu control that accepts keyboard movement. I have a form with a button on it. When I click the button I see my menu pop up below the button. The problem is that the focus shifts between the button and the custom control whenever I press an arrow key. How do I keep other controls from stealing focus away from my custom control. I don't want to disable other controls. I want to maintain focus in my custom control I've tried to set the handled and the suppressKeyPress functionality in the event but the button still grabs focus for every other keypress. Any ideas? Thanks, Brad

      B Offline
      B Offline
      bradsnobar
      wrote on last edited by
      #2

      I found it... here is the magic override... protected override bool IsInputKey(Keys key) {    switch (key)    {      case Keys.Up:      case Keys.Down:      case Keys.Right:      case Keys.Left:      return true;    }    return base.IsInputKey(key); }

      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