VB.NET通知图标和上下文菜单

时间:2014-09-24 13:22:09

标签: vb.net

大家早上好! 我建立了一个热键程序,它很棒。我正在做的是使用my.settings来存储用户想要使用热键的网页链接,一旦他们点击更新,或者最小化,我将我的应用保存到my.settings并最小化到任务托盘。一旦他们从任务托盘上下文菜单中单击“显示应用程序”,它就可以正常加载,但如果他们再次点击“显示应用程序”,它就不会加载窗口,它会将其加载到任务栏,但我无法点击它加载到屏幕以供用户进行更新。以下是我的ONLOAD代码:

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

以下是Show Application上下文菜单的代码:

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

1 个答案:

答案 0 :(得分:0)

这解决了我的问题:将以下内容放在ShowToolStripMenItem_Click

Me.Visible = True
        Me.Opacity = 100
        Me.FormBorderStyle = FormBorderStyle.FixedSingle
        Me.ShowInTaskbar = True
        Me.WindowState = FormWindowState.Normal