我在VB.net中有一个WinForms应用程序,附带 ContextMenu 的 NotifyIcon 。出于某种原因,当我单击菜单项将主窗体设置为Me.TopMost = false
时,然后将批处理文件复制到PC并运行它,NotifyIcon似乎被处理掉(不再出现在系统托盘中)。这似乎只是 断断续续地 ....我不知道是什么导致了这一点。
我认为处理NotifyIcon的原因是因为如果我在操作后添加readerNotify.Visible = True
,图标仍然不会重新出现。请参阅下面的代码
Private Sub ResetWindowsUpdateComponentsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ResetWindowsUpdateComponentsToolStripMenuItem.Click
'Adds Windows Update Components reset batch file to ProgramData and runs the file
Dim fileContent As String = My.Resources.WindowsUpdate_Components_Reset
Dim filename As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\WUCR.bat"
Me.TopMost = False
clearWUCache()
My.Computer.FileSystem.WriteAllText(filename, fileContent, False, System.Text.Encoding.ASCII)
'**WHERE NOTIFYICON SEEMS TO DIE**
Dim objProcess As Process = New Process
objProcess.StartInfo.FileName = filename
objProcess.Start()
objProcess.WaitForExit()
prgBarTemps.Value = 100
lblStatus.Text = "Windows Update components reset successfully!"
Me.TopMost = True
End Sub
Private Sub clearWUCache()
Dim wuCacheFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Windows) & "\SoftwareDistribution\Download"
Try
WebFixProcesses.deleteFolders(wuCacheFolder)
WebFixProcesses.deleteFiles(wuCacheFolder)
Catch ex As Exception
MsgBox(ex.Message)
Dim wuCacheDirect As String = "C:\Windows\SoftwareDistribution\Download"
WebFixProcesses.deleteFolders(wuCacheDirect)
WebFixProcesses.deleteFiles(wuCacheDirect)
lblStatus.Text = "Press a button to fix problems"
End Try
End Sub
我必须在设置批处理文件的方式中设置错误,并设置Me.TopMost = False
或类似的东西。非常感谢任何帮助!
编辑:
以下是NotifyIcon上我的Form.Designer InitializeComponent()方法的一些其他信息。
Private Sub InitializeComponent()
'Have omitted other controls
Me.readerNotify = New System.Windows.Forms.NotifyIcon(Me.components)
'readerNotify
'
Me.readerNotify.ContextMenuStrip = Me.ContextMenu
Me.readerNotify.Icon = CType(resources.GetObject("readerNotify.Icon"), System.Drawing.Icon)
Me.readerNotify.Text = "WebFix"
Me.readerNotify.Visible = True
End Sub
Public WithEvents readerNotify As System.Windows.Forms.NotifyIcon