0

I am new to C#, but I have persevered with it and have made a start on my first proper program. The program consists of a Notify Icon that exists in the Notification area, and when it is clicked, the form will be displayed for a short period.

So far, I have it so the program starts up (without showing the form (which is a FixedSingle so it is only displayed as a grey box), but creating the icon), and registers the MouseClick event, but this is where I have become stuck. I am trying to get it so that when the icon is clicked, the box will appear above/next to the Notification area (until the blur event occurs, or an event from an object on the form), but after googling for the last half an hour or so, I am no closer to finding a solution, probably because I don't know the proper words.

So, does anyone know what commands need to be sent to make the form appear momentarily in the correct coordinates (relative to the notification area)?

Additional

I have modified static void Main() to the following:

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new frmMain();
Application.Run();

so the new frmMain() exists as it's own entity, not as an argument of Application.Run()

Edit

Righto, just found out that I can display the form with this.Show() and that shows the form, and it's converse this.Hide() will hide it. But I still cannot determine the coordinates of the notification area, and how to calculate what the new coordinates of the form for it to be displayed next to/over it.

topherg
  • 4,203
  • 4
  • 37
  • 72
  • Does the answer here help? http://stackoverflow.com/questions/3644315/show-a-winform-over-the-notification-area (Note Hans Passant's reply as well) – keyboardP Apr 16 '13 at 18:01
  • I am on that exact question at this exact moment, I am playing around with the settings, but that will always have the form appearing at the bottom right corner of the screen. So is there a way to detect the position of the taskbar as well so I can add a modifier to chose which corner to assign it to? – topherg Apr 16 '13 at 18:03
  • Finding the position of the Taskbar isn't straightforward but there's a post here (http://winsharp93.wordpress.com/2009/06/29/find-out-size-and-position-of-the-taskbar/). Untested but you could instead get the mouse position within the `NotifyIcon's` click event handler and just position the window around there. – keyboardP Apr 16 '13 at 18:07

1 Answers1

1

You can use:

  1. Screen.PrimaryScreen
  2. Screen.WorkingArea

System.Drawing.Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;
this.Left = workingRectangle.Width - this.Width;
this.Top = workingRectangle.Height - this.Height;
this.Show();

Above code need to be called whenever notification icon is clicked.

Abhinav
  • 2,085
  • 1
  • 18
  • 31