473,395 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to minimize by pressing esc(c#)

I am currently working on a windows form and i want to minimize the form when pressed the escape key , i tried the cancelButton property for form ,and bind the button which is

private void btnHide_Click(object sender, EventArgs e)
{
Hide();
}

pressing the button by mouse hides the form, but pressing esc which is bound with btnHide is not working ,

Is there sth that i am missing ?

Thanks.
Oct 30 '09 #1
5 3611
tlhintoq
3,525 Expert 2GB
A control must have focus for the keypress to go to that control.
You wouldn't want to be in a textbox and hit a key assigned to a button and just have the program take off in an unexpected way.

Your first line says you want to minimize the form. But you are calling the hide method. Did you want to minimize or did you want to hide?

Expand|Select|Wrap|Line Numbers
  1. this.WindowState = FormWindowState.Minimized;
Oct 31 '09 #2
Ok, i understand the problem now, i made the button visible property false , in order not to see it on the form and expect it to work when pressed the escape key.The other problem is now , is there have to be a shown button in order to work this escape key which is bound to that button ?
Oct 31 '09 #3
Yeah i did it,I made the button so small and put where nobody sees it :), but if you have any other solution , you are welcome.

Thanks.
Oct 31 '09 #4
tlhintoq
3,525 Expert 2GB
If you minimize instead of hide you don't have to worry about needing a way to show it.

You might want to look at the NotifyIcon object. That way you can hide or minimize or whatever and put commands in a menu in tasktray icon
Oct 31 '09 #5
Saser
17
Not sure if it's this you're looking for, but anywayz.

Expand|Select|Wrap|Line Numbers
  1. private void Form1_KeyPress(object sender, KeyPressEventArgs e)
  2.         {
  3.             if (e.KeyChar == (char)Keys.Escape)
  4.             {
  5.                 this.WindowState = FormWindowState.Minimized;
  6.             }
  7.         }
Nov 1 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: G520 | last post by:
Hi I have been getting statistical rapports from a machine via a telnet server. Until now it has been done manually. However I want to automate the proccess, and scedule a PHP script to run...
3
by: billie | last post by:
Hi all. I'm searching for a module that permit me to costantly log every key pressed on the keyboard and eventually assign it a function (e.g. when "esc" is pressed: exit program").
17
by: hugo27 | last post by:
hugo27 July 13, 2004 > >The teachy books and documentation I've read do not >mention the Escape key, but everytime I hit it during >runtime my programs go bananas. > >This relates to a larger...
8
by: drose0927 | last post by:
Please help! I can't get my program to exit if the user hits the Escape button: When I tried exit(EXIT_SUCCESS), it wouldn't compile and gave me this error: Parse Error, expecting `'}''...
0
by: Alex K. | last post by:
I do not have any buttons on a form. How do I close it if user presses ESC key? Thanks
2
by: Rudy Ray Moore | last post by:
Visual studio c++ 7.1/.net/2003 got me in the habit of pressing ESC after performing a search using CTRL-F. I've always thought the extra step (pressing ESC) was dumb, but could not come up with...
3
by: Darin | last post by:
How can I get the ESC key to work in a console application? I have: i=console.read if i=27 then {exit my code} end if But, when I hit the ESC key nothing happens. How can I get it to work?
5
by: Micky | last post by:
VB v7.1.3088 NET v1.1.4322 SP1 My mate has a strange problem regarding the ESC key and validation. When he hits the Cancel button on his form, the form does not validate. This is correct...
0
by: John Sheppard | last post by:
Hello there, I was wondering if anyone knew how to close a form when the user presses the esc key. I dont have any buttons on the form so I cannot use the cancelButton property of the form. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.