然後,您需要在表單中關閉甚至調用您的「InterfaceProg_Resize」代碼。
因此,使一個新的子「Private Sub ProgToTray()」
也你不需要嘗試趕上它。
您還需要隱藏任務欄圖標「Me.ShowInTaskbar =假」
並最小化形式「Me.WindowState = FormWindowState.Minimized」
Private Sub ProgToTray()
Me.ShowInTaskbar = False
Me.WindowState = FormWindowState.Minimized
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(1, "Browser Bandwidth Optimizer", "Program Minimized", ToolTipIcon.Info)
End Sub
如果你的表單上的用戶點擊X,然後你需要取消的形式收盤在的FormClosing事件。「e.Cancel =真」
然後調用「ProgToTray()」
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
e.Cancel = True
ProgToTray()
End Sub
然後,如果你關閉與X它會去的形式通知區域。
不要忘記點擊事件再次從通知圖標和選項中打開表單,以便用戶可以退出表單。
要創建退出按鈕,您需要將ContextMenuStrip1添加到窗體。
要打開ContextMenuStrip1當你右鍵點擊將NotifyIcon1你需要添加代碼「ContextMenuStrip1.Show(Cursor.Position)」你將NotifyIcon1單擊事件
您還需要檢查被點擊的按鈕。
「如果e.Button = Windows.Forms.MouseButtons.Right然後」爲正確的按鈕。
和
「e.Button = Windows.Forms.MouseButtons.Left Then」爲左側按鈕。
因此,如果用戶點擊左側,表單將再次打開,當他點擊右側時,將顯示ContextMenuStrip1。
如果用戶單擊鼠標左鍵,將窗體狀態設置恢復正常。
再次顯示任務欄圖標並隱藏托盤圖標。
Private Sub NotifyIcon1_MouseClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseClick
If e.Button = Windows.Forms.MouseButtons.Right Then
ContextMenuStrip1.Show(Cursor.Position)
ElseIf e.Button = Windows.Forms.MouseButtons.Left Then
Me.WindowState = FormWindowState.Normal
Me.ShowInTaskbar = True
NotifyIcon1.Visible = False
End If
End Sub
然後你做出了退出按鈕的點擊事件,並刪除了形式關閉事件「RemoveHandler MyBase.FormClosing,AddressOf Form1_FormClosing」的處理程序。
取消關閉表格不會發生。 然後給我打電話。接近()
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
RemoveHandler MyBase.FormClosing, AddressOf Form1_FormClosing
Me.Close()
End Sub
他將如何關閉他的表格呢? – 2014-11-01 18:47:55
忘了發佈該部分。我現在把它寫在我的答案中。 – Creator 2014-11-01 21:35:42
thx ..它完美的工作。只是一件事,但我已經解決了它。當我使用me.close()程序仍然運行在任務欄事件中時,程序似乎很接近。目前我使用「結束」在我的電腦上的toolstripmenu – user2364790 2014-11-02 16:56:59