Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top