0

Morning everyone! I built a hotkeys program and it works wonderful. What i am doing is using my.settings to store weblinks that users want to use the hotkeys with, once they hit Update, or minimize, i have my app save to my.settings and minimize to the task tray. Once they click "Show Application" from the task tray context menu, it loads fine, but if they go to click "Show Application" again, it doesnt load the window, it loads it to the task bar, but i cant click on it to load to the screen for users to make updates. Below is my code for the 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

Here is my code for the Update button:

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

Here is my code for the Show Application context menu:

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
Derek Napoli
  • 167
  • 1
  • 8
  • 20
  • Seriously? Once they click "Show Application" from the task tray context menu, it loads fine, but if they go to click "Show Application" again, it doesnt load the window, it loads it to the task bar, but i cant click on it to load to the screen for users to make updates. It looks like its storing cache somewhere and wont let me restore it more than once – Derek Napoli Sep 24 '14 at 13:26
  • There's code missing, it isn't clear how the user closes the window again after making it visible. Plenty of problems in this code, high odds that the hotkeys will stop working for example because the Handle property changed. [Look here](http://stackoverflow.com/a/1732294/17034) for guidance. RegisterHotKey() belongs in an override for the OnHandleCreated() method. – Hans Passant Sep 24 '14 at 13:31
  • Once they open it, make their update, they hit a button which is called Update. Update saves the update to my.settings and then minimizes the form to the task tray again. After that point, i cant show the form again, it seems like its getting stuck somewhere – Derek Napoli Sep 24 '14 at 13:34
  • Think i found something. The below code is used to show the form. It works one time and then doesnt load anymore. If i change the FormWindowState to Maximized it works fine and loads everytime, if i change to Normal, it loads to taskbar and im not able to bring it to the screen: Private Sub ShowToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ShowToolStripMenuItem.Click Me.WindowState = FormWindowState.Normal NotifyIcon1.Visible = False Me.Visible = True End Sub – Derek Napoli Sep 24 '14 at 13:43
  • 17 views and no help? Come on... – Derek Napoli Sep 24 '14 at 14:12
  • 1
    You'll have to be patient, give SO users a chance to find a repro on the code you posted. Which is incomplete and contains far too much code that doesn't have anything to do with the problem. You should use the code I linked. A workaround for your code is to set the Visible property to True *before* changing the WindowState. – Hans Passant Sep 24 '14 at 14:18
  • Thank you Hans, that actually worked, but now the application shows in the taskbar, i only want it to show in the task tray. When i change the form properly to false for show in taskbar, the same issue from before happens, it doesnt reload the form. – Derek Napoli Sep 24 '14 at 14:32
  • I already linked to the code that solves that problem. If you don't want to use it then it isn't up to me to provide you a solution. You'll have to be patient. – Hans Passant Sep 24 '14 at 14:38

1 Answers1

0

This fixed my issue: Placed the below in the ShowToolStripMenItem_Click

Me.Visible = True
        Me.Opacity = 100
        Me.FormBorderStyle = FormBorderStyle.FixedSingle
        Me.ShowInTaskbar = True
        Me.WindowState = FormWindowState.Normal
Derek Napoli
  • 167
  • 1
  • 8
  • 20