刚刚创建了一个位于任务栏中的简单应用程序。它显示PC名称,IPV4地址和域。我这样做是为了当用户关闭应用程序时它只关闭托盘,除非从contextmenustrip中选择了EXIT。它工作得很好。然后我添加了一些代码来尝试一些东西,它没有提供太多,所以我删除了它。一旦移除,应用程序停止最小化到托盘。这没有任何意义,因为它与先前的代码完全一样。并且应该禁用maxmimize按钮。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Obtain Hostname and assign to label
strHostname = System.Net.Dns.GetHostName()
lblHostname.Text = strHostname.ToString
'Obtain IP Address and assign to label
Dim ipHostEntry = Dns.GetHostEntry(Dns.GetHostName)
Dim strIpAddress = ipHostEntry.AddressList.FirstOrDefault(Function(ip) ip.AddressFamily = AddressFamily.InterNetwork)
If strIpAddress IsNot Nothing Then
strIpAddress.ToString()
Else
lblIP.Text = "No IPV4 Address could be retrieved"
End If
lblIP.Text = strIpAddress.ToString
'Obtain Domain and assign to label
strDomain = Environment.UserDomainName
lblDomain.Text = strDomain.ToString
End Sub
Private Sub form1_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'This checks to see if the form was closed by the MENU (Boolean = True)
' or if the user selected "X" which will minimize to task tray
'This is needed because X cannot be disabled without losing Minimize function
If BoolClose = False Then
e.Cancel = True
WindowState = FormWindowState.Minimized
Else
End
End If
End Sub
Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
WindowState = FormWindowState.Normal
End Sub
Private Sub NotifyIcon1_MouseClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseClick
WindowState = FormWindowState.Normal
End Sub