Re: close a form by pressing ESC
From: .NET Undertaker (NETUndertaker_at_discussions.microsoft.com)
Date: 09/17/04
- Next message: Josema: "Re: LinkButton.Click"
- Previous message: Richard Blewett [DevelopMentor]: "Re: Reflection problem"
- In reply to: Alex K.: "Re: close a form by pressing ESC"
- Messages sorted by: [ date ] [ thread ]
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
> > >
> > >
> > >
- Next message: Josema: "Re: LinkButton.Click"
- Previous message: Richard Blewett [DevelopMentor]: "Re: Reflection problem"
- In reply to: Alex K.: "Re: close a form by pressing ESC"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|