Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by PlausiblyDamp
  • *Experts*
Posted

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.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

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.

  • *Experts*
Posted
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.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • *Experts*
Posted (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 by DiverDan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

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

  • *Experts*
Posted
How about Form.ActiveForm?

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...