6月 21, 2011

視窗縮小在工作列上


.NET 針對這方面的功能使用一個物件去完成,相較於VB6更顯得簡單。
首先必須在.NET From 上面新增一個 NotifyIcon 物件,在 ToolBox 裡面的 Windows Froms 中可以找到此物件。新增完成後,可以將以下程式放到程式碼中執行。

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

With NotifyIcon1
.Icon = New System.Drawing.Icon("C:\Program Files\Microsoft Visual Studio .NET\Common7\Graphics\icons\Writing\BOOK01A.ICO")
.Visible = False
End With

End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize

If Me.WindowState = FormWindowState.Minimized Then
NotifyIcon1.Visible = True
Me.Visible = False
End If

End Sub

Private Sub NotifyIcon1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
NotifyIcon1.Visible = False
Me.Show()
Me.WindowState = FormWindowState.Normal
End Sub

沒有留言: