0

I am working on a tool that docks primarily in the system tray. However, if the icon is clicked, the form opens for more options displayed on the form. (Not a context menu) However, I want to position the form directly above the system tray and have no clue how to go about doing this. This application will run on multiple user computers with varying screen resolutions, so hard coding a preset coordinate is not a viable solution.

I did search for FindWindow() for the system tray but could not find anything useful out of Google/Bing.

2 Answers2

0

There is a Screen.WorkingArea property which allows you to get the primary screen "available resolution".

Just put your window top at working area height - window height and window left at working area width - window width (and adjust if necessary to get a bit of margin).

Update: Also, account for the taskbar position and size: How do I get the taskbar's position and size?

Community
  • 1
  • 1
thomasb
  • 5,816
  • 10
  • 57
  • 92
0

You could use this:

First Set The form TopMost

MyForm.TopMost = True

To show the form on top of taskbar on right side, here is example:

Private Sub SetFormPosition()
    Dim leftpos As Long
    Dim toppos As Long
    leftpos = (My.Computer.Screen.WorkingArea.Right - 2) - Me.Width
    toppos = (My.Computer.Screen.WorkingArea.Bottom - 2) - Me.Height
    Me.Location = New Point(leftpos, toppos)
End Sub

You can play around and change Values. (-2) is close to edge, if you put bigger number you will be away from the edge and so on. You can also change the My.Computer.Screen.WorkingArea where you want to show the Form.

You can use the code on NotifyIcon_MouseClick Event

  Private Sub NotifyIcon_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon.MouseClick
        If e.Button = Windows.Forms.MouseButtons.Left Then
            SetFormPosition()
            MyForm.Show()
        End If
  End Sub