0
大家早上好! 我建立了一個熱鍵程序,它的工作很棒。我正在做的是使用my.settings來存儲用戶想要使用熱鍵的weblinks,一旦他們點擊更新或最小化,我將我的應用保存到my.settings並最小化到任務托盤。一旦他們從任務托盤上下文菜單中點擊「顯示應用程序」,它就會正常加載,但如果他們再次點擊「顯示應用程序」,它不會加載窗口,它會將其加載到任務欄,但我無法點擊它加載到屏幕上供用戶進行更新。下面是我對ONLOAD代碼:VB.NET通知圖標和上下文菜單
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
tbaltC.Text = My.Settings.altC
tbaltD.Text = My.Settings.altD
tbaltA.Text = My.Settings.altA
tbaltB.Text = My.Settings.altB
tbaltE.Text = My.Settings.altE
tbaltF.Text = My.Settings.altF
tbaltG.Text = My.Settings.altG
tbaltH.Text = My.Settings.altH
tbaltI.Text = My.Settings.altI
tbaltJ.Text = My.Settings.altJ
RegisterHotKey(Me.Handle, 100, MOD_ALT, Keys.D)
RegisterHotKey(Me.Handle, 200, MOD_ALT, Keys.C)
RegisterHotKey(Me.Handle, 300, MOD_ALT, Keys.A)
RegisterHotKey(Me.Handle, 400, MOD_ALT, Keys.B)
RegisterHotKey(Me.Handle, 500, MOD_ALT, Keys.E)
RegisterHotKey(Me.Handle, 600, MOD_ALT, Keys.F)
RegisterHotKey(Me.Handle, 700, MOD_ALT, Keys.G)
RegisterHotKey(Me.Handle, 800, MOD_ALT, Keys.H)
RegisterHotKey(Me.Handle, 900, MOD_ALT, Keys.I)
RegisterHotKey(Me.Handle, 1000, MOD_ALT, Keys.J)
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(1000)
Me.WindowState = FormWindowState.Minimized
Me.Visible = False
End Sub
這裏是我的更新按鈕代碼:
Private Sub btnUPDATE_Click(sender As Object, e As EventArgs) Handles btnUPDATE.Click
My.Settings.altC = tbaltC.Text
My.Settings.altD = tbaltD.Text
My.Settings.altA = tbaltA.Text
My.Settings.altB = tbaltB.Text
My.Settings.altE = tbaltE.Text
My.Settings.altF = tbaltF.Text
My.Settings.altG = tbaltG.Text
My.Settings.altH = tbaltH.Text
My.Settings.altI = tbaltI.Text
My.Settings.altJ = tbaltJ.Text
My.Settings.Save()
MsgBox("Your changes have been saved!", , "Settings")
RegisterHotKey(Me.Handle, 100, MOD_ALT, Keys.D)
RegisterHotKey(Me.Handle, 200, MOD_ALT, Keys.C)
RegisterHotKey(Me.Handle, 300, MOD_ALT, Keys.A)
RegisterHotKey(Me.Handle, 400, MOD_ALT, Keys.B)
RegisterHotKey(Me.Handle, 500, MOD_ALT, Keys.E)
RegisterHotKey(Me.Handle, 600, MOD_ALT, Keys.F)
RegisterHotKey(Me.Handle, 700, MOD_ALT, Keys.G)
RegisterHotKey(Me.Handle, 800, MOD_ALT, Keys.H)
RegisterHotKey(Me.Handle, 900, MOD_ALT, Keys.I)
RegisterHotKey(Me.Handle, 1000, MOD_ALT, Keys.J)
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(1000)
Me.WindowState = FormWindowState.Minimized
Me.Visible = False
End Sub
這裏是我的顯示應用程序上下文菜單代碼:
Private Sub ShowToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ShowToolStripMenuItem.Click
NotifyIcon1.Visible = False
Me.WindowState = FormWindowState.Normal
Me.Visible = True
End Sub
認真嗎?一旦他們從任務托盤上下文菜單中點擊「顯示應用程序」,它就會正常加載,但如果他們再次點擊「顯示應用程序」,它不會加載窗口,它會將其加載到任務欄,但我無法點擊它加載到屏幕上供用戶進行更新。它看起來像它的存儲緩存的地方,並不會讓我不止一次恢復它 – 2014-09-24 13:26:28
有代碼缺失,它不明確如何用戶關閉窗口後,使其可見。在這段代碼中存在很多問題,例如因爲Handle屬性改變,熱鍵將停止工作的可能性很高。 [看這裏](http://stackoverflow.com/a/1732294/17034)的指導。 RegisterHotKey()屬於OnHandleCreated()方法的覆蓋。 – 2014-09-24 13:31:53
一旦他們打開它,進行更新,他們就會點擊一個名爲Update的按鈕。更新將更新保存到my.settings,然後再次將表單最小化到任務托盤。在那之後,我不能再次顯示錶單,它似乎陷入某處 – 2014-09-24 13:34:17