添加一个notifyIcon控件
vb.net
Private Sub vbFormTest_Resize(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Resize
If WindowState = FormWindowState.Minimized Then
Me.Visible = False
Me.NotifyIcon1.Visible = True
End If
End Sub
Private Sub NotifyIcon1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles NotifyIcon1.Click
Me.Visible = True
NotifyIcon1.Visible = False
Me.WindowState = FormWindowState.Normal
End Sub
c#.net
//调整窗体大小的时候,如果是最小化,窗体不显示,在托盘中显示
private void Form1_Resize(object sender,EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Visible = false;
this.notifyIcon1.Visible = true;
}
}
//如果点击托盘中的窗体图标,则窗体显示,托盘中的图标隐藏
private void notifyIcon1_Click(object sender,EventArgs e)
{
this.Visible = true;
this.notifyIcon1.Visible = false;
WindowState = FormWindowState.Normal; }