简体   繁体   中英

Handle windows calls with in .net program?

I have an application which runs on click of tray icon in windows( developed in C#). I want to minimise the application on click of escape button. how do i accomplish this ?

Thanks in advance, Ravi Naik.

There are several ways to achieve this. One is to set the KeyPreview property of the form to true , and have the following KeyDown event handler:

private void Form_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Escape)
    {
        this.WindowState = FormWindowState.Minimized;
    }
}

Another approach is to have a button that will minimize the form in its Click event, and point that button out in the form's CancelButton property.

You need to override IsInputKey and return true for handling the escape. Then you can add the handler for KeyDown event and do the minimize operation.

If on the click of a particular button you want the application to minimize to tray then take a look at NotifyIcon class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM