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. Catch Enter-key when focus on a button

Catch Enter-key when focus on a button

Scheduled Pinned Locked Moved C#
questionhelp
4 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
    mSh1985
    wrote on last edited by
    #1

    I have some strange problem here, so i was wondering if i could solve it in this way (i know it's not the best way to solve a problem, but i want a quick and dirty solution at the moment) Let's say i have a button, with the focus on it. When i press the button a messagebox is shown. I only want the messagebox to be shown when i press the button with my mouse. When i press enter i don't want the messagebox to be shown. So i tried handling the keypress method and set the eventargs e.handled=true. But no effect, it doesn't even get inside the keypress method when pressing enter... I know it's a strange question, but anyone have any ideas? Thanks in advance.

    M I M 3 Replies Last reply
    0
    • M mSh1985

      I have some strange problem here, so i was wondering if i could solve it in this way (i know it's not the best way to solve a problem, but i want a quick and dirty solution at the moment) Let's say i have a button, with the focus on it. When i press the button a messagebox is shown. I only want the messagebox to be shown when i press the button with my mouse. When i press enter i don't want the messagebox to be shown. So i tried handling the keypress method and set the eventargs e.handled=true. But no effect, it doesn't even get inside the keypress method when pressing enter... I know it's a strange question, but anyone have any ideas? Thanks in advance.

      M Offline
      M Offline
      mSh1985
      wrote on last edited by
      #2

      wow this must be the dumbest question i've ever asked here... I could just use the mouseclick event, problem solved :laugh: :laugh: :laugh:

      1 Reply Last reply
      0
      • M mSh1985

        I have some strange problem here, so i was wondering if i could solve it in this way (i know it's not the best way to solve a problem, but i want a quick and dirty solution at the moment) Let's say i have a button, with the focus on it. When i press the button a messagebox is shown. I only want the messagebox to be shown when i press the button with my mouse. When i press enter i don't want the messagebox to be shown. So i tried handling the keypress method and set the eventargs e.handled=true. But no effect, it doesn't even get inside the keypress method when pressing enter... I know it's a strange question, but anyone have any ideas? Thanks in advance.

        I Offline
        I Offline
        Islorvat
        wrote on last edited by
        #3

        Hello! I am quite new to programming. I have no ideea how to cancel these 'automatic' key events that rise from hiting 'enter' or 'space' on a button but here is how i would do it: Set button's 'TabStop' to false. Create an 'enter' event and put this inside the event: SelectNextControl(yourbuttoncontrolhere, true, true, true, true); This won't allow the user to focus the control in any way but it will allow him to click the button. Hope this helps, Good luck!

        1 Reply Last reply
        0
        • M mSh1985

          I have some strange problem here, so i was wondering if i could solve it in this way (i know it's not the best way to solve a problem, but i want a quick and dirty solution at the moment) Let's say i have a button, with the focus on it. When i press the button a messagebox is shown. I only want the messagebox to be shown when i press the button with my mouse. When i press enter i don't want the messagebox to be shown. So i tried handling the keypress method and set the eventargs e.handled=true. But no effect, it doesn't even get inside the keypress method when pressing enter... I know it's a strange question, but anyone have any ideas? Thanks in advance.

          M Offline
          M Offline
          Md Marufuzzaman
          wrote on last edited by
          #4

          I dont understand why you fired button1_Click event....just fired button1_MouseClick event that's it..

          Thanks Md. Marufuzzaman


          Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

          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