Search code examples
c#winformsnotificationstaskbartrayicon

How to set the location of a notification custom form just above or below depending on the position of the system Tray Icon of the Taskbar?


Is there a way to recognize the position of system tray in c# winforms?

enter image description here

I want to create a form that will place above or below the system tray depends on where the system tray is the position.

I am planning to create a custom form instead of a context menu since I need to enhance the UI but I am confused about how will position my form above/below the system tray.

I attached the image of how I imagine my form will be position.


Solution

  • I tried to look at your references and I had an idea based on that and here is the fix:

    1. Created notifyicon control then set is method on click method to call my form
    2. The form will be displayed above the position of the mouse since the notifyicon control is always placed on the system tray whatever the position of the toolbox might be.

    Code snippet for position your form via mouse position

     var form = new Form1();
                        form.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
                        form.SetDesktopLocation(MousePosition.X - form.Width / 2, MousePosition.Y - form.Height - 20);
                        form.Show();
                        form.Activate();
                        form.TopMost = true;