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. Dialog box exit

Dialog box exit

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

    I have a modal dialog box with AcceptButton & CancelButton Is there a way to test if the dialog was closed with the user pressing 'Enter' as apposed to using the mouse to click either of the buttons or the control box? MyDialog dlg = new MyDialog(); DialogResult rc = dlg.ShowDialog(); if(dlg.wasEnterPressed()) ... The 'Click' event on the AcceptButton fires for both mouse & keypress. I tried to look at the KeyDown event but that doesn't fire when 'Enter' is pressed.

    A 1 Reply Last reply
    0
    • B baronics

      I have a modal dialog box with AcceptButton & CancelButton Is there a way to test if the dialog was closed with the user pressing 'Enter' as apposed to using the mouse to click either of the buttons or the control box? MyDialog dlg = new MyDialog(); DialogResult rc = dlg.ShowDialog(); if(dlg.wasEnterPressed()) ... The 'Click' event on the AcceptButton fires for both mouse & keypress. I tried to look at the KeyDown event but that doesn't fire when 'Enter' is pressed.

      A Offline
      A Offline
      Ashok Dhamija
      wrote on last edited by
      #2

      As you have an AcceptButton, it appears that the Click event of the OK button precedes the KeyDown event for the Enter key and kills the dialog box before the KeyDown event fires. Try NOT declaring the AcceptButton and then see whether the KeyDown event fires for the Enter key. Regards, Ashok Dhamija _____________________________ Padam Technologies

      B 1 Reply Last reply
      0
      • A Ashok Dhamija

        As you have an AcceptButton, it appears that the Click event of the OK button precedes the KeyDown event for the Enter key and kills the dialog box before the KeyDown event fires. Try NOT declaring the AcceptButton and then see whether the KeyDown event fires for the Enter key. Regards, Ashok Dhamija _____________________________ Padam Technologies

        B Offline
        B Offline
        baronics
        wrote on last edited by
        #3

        Thanks. The solution I went with was to add: protected override bool ProcessCmdKey(ref System.Windows.Forms.Message m, Keys k) { if(k == Keys.Enter) bEnterPressed = true; return false; }

        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