Howdy, I have a notify icon that opens a window. To openthe windowyou can either click 'Open' in the icons context menu or just double click on the icon. The menu option is fine, but whenever I use the double click feature, the window opens but doesn't come to the front and doesn't have focus. It must be something with the second mouse click releasing focus but I have no idea how to right this. Any suggestions?
Both events (the menu click and the icon double click) rasie the following event:
Private Sub itmOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles itmOpen.Click, nfyNotify.MouseDoubleClick
Me.WindowState = FormWindowState.Normal
Me.ShowInTaskbar = True
Me.BringToFront()
Me.Focus()
End Sub |
| Hoopla Saturday, July 29, 2006 10:15 AM |
In stead of BringToFront(), try calling SetForegroundWindow(Me.Handle). Add this declaration: Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hWnd As IntPtr) As Boolean
|
| nobugz Sunday, July 30, 2006 3:17 AM |
| Hoopla wrote: | |
Howdy, I have a notify icon that opens a window. To openthe windowyou can either click 'Open' in the icons context menu or just double click on the icon. The menu option is fine, but whenever I use the double click feature, the window opens but doesn't come to the front and doesn't have focus. It must be something with the second mouse click releasing focus but I have no idea how to right this. Any suggestions?
Both events (the menu click and the icon double click) rasie the following event:
Private Sub itmOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles itmOpen.Click, nfyNotify.MouseDoubleClick
Me.WindowState = FormWindowState.Normal
Me.ShowInTaskbar = True
Me.BringToFront()
Me.Focus()
End Sub |
|
BringToFront will only bring the application to the front if the Form it is used upon does not have a parent. |
| Peter Ritchie Saturday, July 29, 2006 5:16 PM |
Regardless of whether the Form has a parent (which it doesn't), the fact still remains that the Form will quite happily come to front when I click on the menu item but wont when I double click the icon. IfI make a timer with a big enough interval that calls BringToFront()and is enabled when I double click the icon, it will quite happily BringToFront() but it's messy and I'm sure there must be a better way. |
| Hoopla Sunday, July 30, 2006 2:55 AM |
In stead of BringToFront(), try calling SetForegroundWindow(Me.Handle). Add this declaration: Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hWnd As IntPtr) As Boolean
|
| nobugz Sunday, July 30, 2006 3:17 AM |
Legend! All praisenobugz. |
| Hoopla Sunday, July 30, 2006 8:13 AM |
I know that this is a very old thread, but if you do not want to import the windows API intoyour code (which marries your codeto the Windows OS), you could instead toggle the Form.TopMost value. Simply set it to true, then back to false, ie:
Code Block
Form form;
form.TopMost = true;
form.TopMost = false;
- Proposed As Answer byMario Montes Friday, March 27, 2009 12:30 PM
-
|
| JaysonGo Friday, December 14, 2007 10:55 PM |
tx that worked! |
| AdrianZ Wednesday, October 07, 2009 4:34 AM |