Re: close a form by pressing ESC

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: .NET Undertaker (NETUndertaker_at_discussions.microsoft.com)
Date: 09/17/04


Date: Fri, 17 Sep 2004 01:27:05 -0700

hi Alex

I have a proposition for you , Check out this code :

        protected override bool ProcessDialogKey(Keys keyData)
                {
                        switch(keyData)
                        {
                                case Keys.D : //Do something break;
                        }
                        return base.ProcessDialogKey (keyData);

you can Trap any key and process the request

"Alex K." wrote:

> I found out why: I had invisible button designated as CancelButton in the
> form. Somehow, the button spoiled the process: it didn't repond because it
> was invisible, and didn't allow the form to respond. After I removed the
> button, KeyDown events works fine (but not KeyPress).
>
> Thanks
> Alex
>
> "Alex K." wrote:
>
> > I tried that; it didn't work. Event even is not fired. I tried also KeyDown
> > event, it responded to all keys except ESC. ??
> >
> >
> > "Tarakeshwar L" wrote:
> >
> > > Hi,
> > >
> > > What you could do is in the Key press event of ur form u could check if the
> > > key pressed is escape. If escape is pressed then do Application.Exit() or
> > > write whatever ever code you would want to run there.
> > >
> > > private void Form1_KeyPress(object sender,
> > > System.Windows.Forms.KeyPressEventArgs e)
> > > {
> > > if(e.KeyChar == (char)27)
> > > Application.Exit();
> > > }
> > >
> > > --
> > > Tarkeshwar
> > > CCIE Q(Routing and Switching)
> > > Fifth Generation Technologies
> > >
> > > "Alex K." <AlexK@discussions.microsoft.com> wrote in message
> > > news:491200E5-10AC-4C08-9A0A-64EF773BAC2D@microsoft.com...
> > > > I do not have any buttons on a form. How do I close it if user presses ESC
> > > key?
> > > > Thanks
> > >
> > >
> > >



Relevant Pages

  • Re: Server/Client Side Rules Not Working?
    ... "Alex" wrote in news:110fb01c3f560$bfe11290 ... > side rules AND they will trigger! ... > Somehow I have the feeling it is rights related, ...
    (microsoft.public.exchange.admin)
  • Re: A new career...?!
    ... and all the attention span of a three-year-old with a sugar high in a toy factory. ... Once again, Alex & I agree:) ... But somehow, the STATE, by virtue of it's having paper credentials, is immune from ...
    (alt.smokers.cigars)
  • Re: A decent thread on medieval history - ADR says 1066 was insignificant
    ... did it got distorted to talk about all things English again??? ... England in 1066 were significant. ... Somehow, Alex has taken this to 18th ...
    (soc.history.medieval)
  • Re: IDE Crashes related to code folding?
    ... Heheh, somehow this same thread is going on in bcb.non-tech, and Alex ... also said Delphi was in C. ...
    (borland.public.delphi.non-technical)
  • Re: A new career...?!
    ... and all the attention span of a three-year-old with a sugar high in a toy ... factory. ... But somehow, the STATE, by virtue of it's having paper credentials, is immune from ... No, I'm pretty sure Alex & I agree on this one, too. ...
    (alt.smokers.cigars)