0

I am writting an application that uses NotifyIcon in C#. I want when user clicks on the NotifyIcon on the system tray (bottom-right of the screen) a notification form (this is not the mainform, it's only a minor form that is used to show notification) will show up at the location of NotifyIcon as Dropbox do: enter image description here

I have used the event MouseClick of NotifyIcon and wrote as follows:

private void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
{
    Form2 form = new Form2();
    form.SetDesktopLocation(MousePosition.X - form.Width/2,MousePosition.Y-form.Height-20);
    form.Show();
    form.Focus();
 }

but it does not work as expected, the notification form show up at the location of main form not at the location of NotifyIcon.

can anybody can help me:|

khaimaitien
  • 51
  • 1
  • 7

1 Answers1

1

Go to Form2 design, select properties of Form2. Look for StartPosition in properties of Form2, set StartPosition as Manual or you can do it as

Form2 form = new Form2();
form.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
form.SetDesktopLocation(MousePosition.X - form.Width/2,MousePosition.Y-form.Height-20);
form.Show();
form.Focus();

Hope this you solve your issue.

Zaksh
  • 953
  • 2
  • 12
  • 29