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. KeyDown event for a button??

KeyDown event for a button??

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

    Hello, I'm creating a slider-like control based in UserControl. Since the UserControl can't receive keyboard events (At least not that I manage to catch), I use a button as the slider handle since that can receive focus (I want to be able to run the slider up/down with the keys that's what I need the key focus for...) First I tried listening to the KeyDown event from the button, but that doesn't get fired, only the KeyUp.. Has it something to do with that the button filters away these events and fires Click instead? So I grab the button and check what messages it receives with spy++, and it says both WM_KEYDOWN and WM_KEYUP (repeated WM_KEYDOWN when key is held down as would be expected). So I override the button and it's wndproc to listen for these events, and also override the onpaint to get rid of the 'click' effect that I don't want. BUT: the wndproc doesn't reveice any WM_KEYDOWN (0x0100) messages. So where are they going and how can I get them? Is there some kind of preprocessmessage-like function that receives and filters these events? Or is there another control I can override instead of a button, that can get keyboard focus. Also, the button still has it's click behaviour that I don't want... Can anyone help me with the right way to go??

    H 1 Reply Last reply
    0
    • M misterbear

      Hello, I'm creating a slider-like control based in UserControl. Since the UserControl can't receive keyboard events (At least not that I manage to catch), I use a button as the slider handle since that can receive focus (I want to be able to run the slider up/down with the keys that's what I need the key focus for...) First I tried listening to the KeyDown event from the button, but that doesn't get fired, only the KeyUp.. Has it something to do with that the button filters away these events and fires Click instead? So I grab the button and check what messages it receives with spy++, and it says both WM_KEYDOWN and WM_KEYUP (repeated WM_KEYDOWN when key is held down as would be expected). So I override the button and it's wndproc to listen for these events, and also override the onpaint to get rid of the 'click' effect that I don't want. BUT: the wndproc doesn't reveice any WM_KEYDOWN (0x0100) messages. So where are they going and how can I get them? Is there some kind of preprocessmessage-like function that receives and filters these events? Or is there another control I can override instead of a button, that can get keyboard focus. Also, the button still has it's click behaviour that I don't want... Can anyone help me with the right way to go??

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      A UserControl is for composite controls (i.e., controls made-up of other controls). It's not really a good base class in this case, and is designed to receive notifications from its children. There are lots of articles here on CodeProject about custom slider controls. I recommend taking a look at some to get some better ideas (without going into a long, unnecessary discussion here) to help you along. http://www.codeproject.com/info/search.asp?cats=3&cats=5&searchkw=slider[^]

      Microsoft MVP, Visual C# My Articles

      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