Nazgulled Posted September 8, 2004 Posted September 8, 2004 (edited) Hi, I have an application with a tray icon that when clicked it will display or hide the form like this: Private Sub notifyIcon_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles notifyIcon.MouseUp If (e.Button = MouseButtons.Left) Then If (Me.Visible = True) Then slideNotesForm(True) Else slideNotesForm(False) End If End If End Sub Private Sub slideNotesForm(ByVal slideout As Boolean) If (slideout = True) Then Me.Location = New Point(scrWidth, ((scrHeight / 2) - (Me.Height / 2))) Me.Hide() Else Me.Location = New Point((scrWidth - Me.Width), ((scrHeight / 2) - (Me.Height / 2))) Me.Show() Me.BringToFront() Me.Activate() End If End Sub Bu supposing the form is visible but I have one or several applications in the front of this application, if I click the notify icon, the form will be hiddne and not shown. How do I check the form focus so I can control this behaviour? Edited November 26, 2005 by PlausiblyDamp Quote
jccorner Posted September 8, 2004 Posted September 8, 2004 Have you thought about checking the form using activeform?? Not quite sure what you mean by several applications in front of it though. Quote Applying computer technology is simply finding the right wrench to pound in the correct screw
*Experts* DiverDan Posted September 8, 2004 *Experts* Posted September 8, 2004 You might try Me.TopMost = True, then in the form's activation event reset Me.TopMost to false. btw, looking as your code I think I found some potentical problems. You might want to change ((scrHeight / 2) - (Me.Height / 2)) to CInt((scrHeight - Me.Height) / 2). This not only increases the accuracy of the form's location to +- 1 pixel instead of +- 2 pixels, but also eliminates a possible problem if scrHeight or Me.Height is an odd number. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Nazgulled Posted September 8, 2004 Author Posted September 8, 2004 ActiveForm won't wokr coz I tried to output it with debug.writeline and blakn line was written in the output window... Let me see if I can explain it better: I have an application with a tray icon. The form at the start is visible, I click on the icon and I hide the form, I click again on the icon and the form will be visible again, I click agian and this time I'll hide it and this on and on... This behaviour is fine if I don't havy anything open besides explorer. But suppose I'm surfing the web, the browser window is maximized and at this time the fomr state of my application is visible and if I click on the tray icon the form will hide and I don't want that, I want the form to remain visible and I want it on top of everything. Quote
*Experts* DiverDan Posted September 8, 2004 *Experts* Posted September 8, 2004 Try my last post with Me.TopMost = True as this will set your form above all other forms. Using Me.ActiveForm will cause your program to crash if another program is active at the time. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Nazgulled Posted September 8, 2004 Author Posted September 8, 2004 I didn't exactly understood what you want me to try... Quote
*Experts* DiverDan Posted September 9, 2004 *Experts* Posted September 9, 2004 (edited) Private Sub notifyIcon_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles notifyIcon.MouseUp If e.Button = MouseButtons.Left Then If Me.Visible = True Then slideNotesForm(True) Else : slideNotesForm(False) End If End If End Sub Private Sub slideNotesForm(ByVal slideout As Boolean) If slideout Then Me.Location = New Point(scrWidth, CInt((scrHeight - Me.Height) / 2) Me.Hide() Else Me.Location = New Point(scrWidth - Me.Width, CInt((scrHeight - Me.Height) / 2) Me.Show() Me.TopMost = True End If End Sub Then in the form's Activated event change the TopMost value to false so that other programs can be displayed above it. Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated Me.TopMost = False End Sub I haven't tested this, but I think it should work for you. Edited September 9, 2004 by DiverDan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Nazgulled Posted September 9, 2004 Author Posted September 9, 2004 it doesn't work... I tried and tried but can't find a way to dit... I need a vraible wich tells me if the form has focus or not... with that it was pretty simple but I guess there's no such thing... at least I can't find it :S Quote
*Experts* Bucky Posted September 9, 2004 *Experts* Posted September 9, 2004 How about Form.ActiveForm? Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Nazgulled Posted September 9, 2004 Author Posted September 9, 2004 that variable is always empty, after fomr.hide() or after form.show() and if I have focus or not on the form, it's always empty... Quote
Nazgulled Posted September 9, 2004 Author Posted September 9, 2004 Everyone forget this... I'll code my application differently, thanks anyway to everyone that tried to help me :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.