這是在伊莉討論區一個網友提出來的問題,要解決這個問題的原理是這樣的:
按下視窗右上角的關閉鈕會呼叫OnFormClosing跟OnFormClosed這兩個方法,然後這兩個方法又要去呼叫FormClosing跟FormClosed這兩個事件,所以要達成我們的功能,就得複寫掉OnFomClosing或OnFormClosed這兩個方法。語法如下:
Friend WithEvents notifyIcon1 As System.Windows.Forms.NotifyIcon Protected Overrides Sub OnFormClosing(ByVal e As FormClosingEventArgs) e.Cancel = True Me.components = New System.ComponentModel.Container Me.notifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components) notifyIcon1.Icon = New Icon("C:\Dev-Cpp\Icons\Book.ico") notifyIcon1.Visible = True Me.Visible = False End Sub
按兩下icon把Form叫出來可以這樣寫:
Private Sub ntfSystemInfo_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles notifyIcon1.DoubleClick NotifyIcon1.Visible = False Me.Show() End Sub
全站熱搜