Code #1
Copy Code code as follows:
private void Form1_sizechanged (object sender, EventArgs e)//Minimize hidden form
{
if (this. WindowState = = formwindowstate.minimized)//form state is minimized
{
stoprecttimer.enabled = false;
This. Visible = false;
This.notifyIcon1.Visible = true; Show system tray icon
This.notifyIcon1.Text = this. Text; Set the text that the icon displays
This. ShowInTaskbar = false; The form is hidden in the task mark
Reghotkey ();
Open Otoolstripmenuitem.text = "open (&o)";
}
}
Obviously, if you open the lyric state, how can you minimize the size of the form without changing it? I think of overloading "minimize", but how to overload it? A scheme for overloading WndProc is given here:
Copy Code code as follows:
const int wm_syscommand = 0x112;
Const int sc_close = 0xf060;
Const int sc_minimize = 0xf020;
Const int sc_maximize = 0xf030;
protected override void WndProc (ref message m)
{
if (m.msg = = Wm_syscommand)
{
if (m.wparam.to Int32 () = = Sc_minimize)
{
this. Visible = false;
return;
}
}
base. WndProc (ref m);
}