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. Scroll Bar hogging focus

Scroll Bar hogging focus

Scheduled Pinned Locked Moved C#
question
6 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.
  • R Offline
    R Offline
    rocky_pulley
    wrote on last edited by
    #1

    Hi, I'm creating a control, I do painting on the form and it has 1 scroll bar control, no other controls on it. I have a keyDown/keyUp handler and they work just fine until I hit the arrow keys, then the scroll bar grabs the key focus and I can't get it back. How can I stop the scrollbar from getting the key focus, I don't want it to be able to grab the key focus at all. Thanks! -- Rocky Dean Pulley

    J 1 Reply Last reply
    0
    • R rocky_pulley

      Hi, I'm creating a control, I do painting on the form and it has 1 scroll bar control, no other controls on it. I have a keyDown/keyUp handler and they work just fine until I hit the arrow keys, then the scroll bar grabs the key focus and I can't get it back. How can I stop the scrollbar from getting the key focus, I don't want it to be able to grab the key focus at all. Thanks! -- Rocky Dean Pulley

      J Offline
      J Offline
      John Fisher
      wrote on last edited by
      #2

      One common way of handling this sort of issue is to subscribe to the Focus events (GotFocus, LostFocus). When the focus changes, detect whether the focus fits with your plan (using the Focused property, if needed). Then, adjust the focus back to where you want it. Of course, you'll need to test things out. It may be that the auto-adjustement of focus has side effects that will take extra effort to work around. John
      "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

      R 1 Reply Last reply
      0
      • J John Fisher

        One common way of handling this sort of issue is to subscribe to the Focus events (GotFocus, LostFocus). When the focus changes, detect whether the focus fits with your plan (using the Focused property, if needed). Then, adjust the focus back to where you want it. Of course, you'll need to test things out. It may be that the auto-adjustement of focus has side effects that will take extra effort to work around. John
        "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

        R Offline
        R Offline
        rocky_pulley
        wrote on last edited by
        #3

        Thanks, but it looks like neither the UserControl class nor the VScrollBar class has these events available. -- Rocky Dean Pulley

        J 1 Reply Last reply
        0
        • R rocky_pulley

          Thanks, but it looks like neither the UserControl class nor the VScrollBar class has these events available. -- Rocky Dean Pulley

          J Offline
          J Offline
          John Fisher
          wrote on last edited by
          #4

          The UserControl definitely has GotFocus and LostFocus. If you are looking only in the property editor of VS, you might not see them. But, the are available if you write the code yourself: userControl.GotFocus += new .... John
          "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

          R 1 Reply Last reply
          0
          • J John Fisher

            The UserControl definitely has GotFocus and LostFocus. If you are looking only in the property editor of VS, you might not see them. But, the are available if you write the code yourself: userControl.GotFocus += new .... John
            "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

            R Offline
            R Offline
            rocky_pulley
            wrote on last edited by
            #5

            thanks, that worked. -- Rocky Dean Pulley

            J 1 Reply Last reply
            0
            • R rocky_pulley

              thanks, that worked. -- Rocky Dean Pulley

              J Offline
              J Offline
              John Fisher
              wrote on last edited by
              #6

              Great! John
              "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

              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