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. Listening to program events.

Listening to program events.

Scheduled Pinned Locked Moved C#
questionwinforms
5 Posts 3 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
    Muntyness
    wrote on last edited by
    #1

    How do I listen for program events? At the moment when listening for key presses, it only works on user controls that have the keypress event set up. How can I get the program to listen to the keypress event that occus in all of a single forms child controls. E.g. so if the form has 5 different user controls, is there a way to set up the even in the form so that if the key is pressed while any of the child controls have focus, the event in the main form is still called? - Munty

    D D 2 Replies Last reply
    0
    • M Muntyness

      How do I listen for program events? At the moment when listening for key presses, it only works on user controls that have the keypress event set up. How can I get the program to listen to the keypress event that occus in all of a single forms child controls. E.g. so if the form has 5 different user controls, is there a way to set up the even in the form so that if the key is pressed while any of the child controls have focus, the event in the main form is still called? - Munty

      D Offline
      D Offline
      Dave Herren
      wrote on last edited by
      #2

      Assign all of the child controls keypress events to the forms keypress event handler. Note that this would not actually raise the forms event. If you needed that you may be able to call the forms keypress event (using the RaiseEvent statement) from the event handlers of each of the controls.

      topcoderjax - Remember, Google is your friend.

      M 1 Reply Last reply
      0
      • D Dave Herren

        Assign all of the child controls keypress events to the forms keypress event handler. Note that this would not actually raise the forms event. If you needed that you may be able to call the forms keypress event (using the RaiseEvent statement) from the event handlers of each of the controls.

        topcoderjax - Remember, Google is your friend.

        M Offline
        M Offline
        Muntyness
        wrote on last edited by
        #3

        The problem with that, is that the KeyPress events don't seem to work on the User controls that edit their Graphics. (Button Click events do, but I need keypress events.) That's why I was hoping there's some way of making shortcut keys from the parent form. - Munty

        1 Reply Last reply
        0
        • M Muntyness

          How do I listen for program events? At the moment when listening for key presses, it only works on user controls that have the keypress event set up. How can I get the program to listen to the keypress event that occus in all of a single forms child controls. E.g. so if the form has 5 different user controls, is there a way to set up the even in the form so that if the key is pressed while any of the child controls have focus, the event in the main form is still called? - Munty

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Enable the KeyPreview property on the form, then handle the forms KeyDown/KeyPress/KeyUp events. The form will get first look at the key events before they're sent to the child controls.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Enable the KeyPreview property on the form, then handle the forms KeyDown/KeyPress/KeyUp events. The form will get first look at the key events before they're sent to the child controls.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            M Offline
            M Offline
            Muntyness
            wrote on last edited by
            #5

            Hi Dave, Thanks for the reply. That was exactly what I needed. Silly thing is, is that I had already tried that, and it didn't work the first time. Then after you suggested it, I decided to try it again. But I've got it working now :) - Munty

            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