Dialog: Cancel button / esc key (Windows forms)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WP

    Dialog: Cancel button / esc key (Windows forms)

    Hello, a short question: Do I have to add a cancel button to my form
    dialog for it to be closable by the esc key? Right now I have no
    cancel button in my dialog and I noticed the esc key will not close
    it. First I thought the two textboxes I have in the dialog "consumed"
    the esc key press but I removed them and the dialog still doesn't
    close when the esc key is pressed so that was not it.

    - Eric
  • twoj wladca

    #2
    Re: Dialog: Cancel button / esc key (Windows forms)

    private void Form1_KeyPress( object sender, KeyPressEventAr gs e)
    {
    if (e.KeyChar == (char)27)
    Application.Exi t();
    }

    Uzytkownik "WP" <mindcooler@gma il.comnapisal w wiadomosci
    news:397efa4a-6c85-4907-9e03-72eea0493065@i2 9g2000prf.googl egroups.com...
    Hello, a short question: Do I have to add a cancel button to my form
    dialog for it to be closable by the esc key? Right now I have no
    cancel button in my dialog and I noticed the esc key will not close
    it. First I thought the two textboxes I have in the dialog "consumed"
    the esc key press but I removed them and the dialog still doesn't
    close when the esc key is pressed so that was not it.
    >
    - Eric

    Comment

    • Peter Duniho

      #3
      Re: Dialog: Cancel button / esc key (Windows forms)

      On Fri, 14 Mar 2008 14:36:51 -0700, twoj wladca <kriz@vp.plwrot e:
      private void Form1_KeyPress( object sender, KeyPressEventAr gs e)
      {
      if (e.KeyChar == (char)27)
      Application.Exi t();
      }
      If you are going to follow this technique, Eric (and it seems from your
      other post you're not), I'd recommend handling instead the KeyDown event,
      and comparing against Keys.Escape rather than the above.

      Noting also, of course, that for simply closing a dialog box, calling
      Application.Exi t() is probably overkill. :)

      Pete

      Comment

      • WP

        #4
        Re: Dialog: Cancel button / esc key (Windows forms)

        On 14 Mar, 23:18, "Peter Duniho" <NpOeStPe...@nn owslpianmk.comw rote:
        On Fri, 14 Mar 2008 14:36:51 -0700, twoj wladca <k...@vp.plwrot e:
        private void Form1_KeyPress( object sender, KeyPressEventAr gs e)
        {
        if (e.KeyChar == (char)27)
        Application.Exi t();
        }
        >
        If you are going to follow this technique, Eric (and it seems from your
        other post you're not), I'd recommend handling instead the KeyDown event,
        and comparing against Keys.Escape rather than the above.
        >
        Noting also, of course, that for simply closing a dialog box, calling
        Application.Exi t() is probably overkill. :)
        >
        Pete
        No, I am not going down that road even though I appreciate people
        trying to help me. But I can't help thinking that that code looks like
        my very simple key handlers I wrote in pure C when doing glut-
        programming. :)

        Comment

        Working...