开发者

How can I tell when a user minimizes the form? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

(C#) How to detect when a windows form is being minimized

First of all my code:

private void Form1_Load(object sender, EventArgs e)
        {
            th开发者_开发技巧is.MinimumSizeChanged += new EventHandler(Form1_MinimumSizeChanged);
        }

        void Form1_MinimumSizeChanged(object sender, EventArgs e)
        {
            MessageBox.Show("1");
        }

so, my program idea is, when the program get minized i will do a system tray, but this event never happnd. how can i know when the user do a minize screen(minize the program).

i have tryed everything. any ideas?


MinimumSizeChanged has nothing to do with the form getting minimized. MinimumSizeChanged has to deal with when the MinimumSize properties of the form are changed.

You want to check the Resize event of the form.


In order to minimize to the system tray, add a NotifyIcon control to your form. Now, override the OnResize method and check if your WindowState property is set to FormWindowState.Minimized. If it is, Hide() your forms and show your notify icon. Make sure to set the Icon property of the NotifyIcon as well. Now just reverse the process for the case when the form is restored.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜