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. OnKeyPress and KeyPress

OnKeyPress and KeyPress

Scheduled Pinned Locked Moved C#
question
3 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
    mihksoft
    wrote on last edited by
    #1

    Hy Can anybody tell me what is the difference between KeyPress event and OnKeyPress override? Why we need both? Why don't work in the same time, only one run? thx

    T M 2 Replies Last reply
    0
    • M mihksoft

      Hy Can anybody tell me what is the difference between KeyPress event and OnKeyPress override? Why we need both? Why don't work in the same time, only one run? thx

      T Offline
      T Offline
      TJoe
      wrote on last edited by
      #2

      The KeyPress event can be used by the associated class or other classes. For example, a Form can listen for key pressed on a TextBox that it contains. The OnKeyPress method is used to fire the KeyPress event. This can only be used by dervied types. So if you create a custom TextBox (say MyTextBox), then you can override the OnKeyPress to catch key presses, alter when the KeyPress event is fired, fire another event, etc.

      Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

      1 Reply Last reply
      0
      • M mihksoft

        Hy Can anybody tell me what is the difference between KeyPress event and OnKeyPress override? Why we need both? Why don't work in the same time, only one run? thx

        M Offline
        M Offline
        Martin 0
        wrote on last edited by
        #3

        Hello, Way 1) OnKeyPress ist the virtual method of a class, which can be overriden from an inherited class. Way 2) For handling the KeyPress event, you do not have to inherit a class. You instanciate a class and handle the delegate.

        All the best, Martin

        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