Solved

C# : Taskbar Location

Posted on 2007-03-28
3
1,507 Views
Last Modified: 2007-12-19
Hi,
I'm working in C#. I have created an application that runs in the system tray. When the user double-clicks the try  icon, a small form comes up in the bottom right corner of the screen, i.e. right above the system tray. The form is basically "sticky" to the tray.

Here is my question: How do I accomplish the same thing, even if the user has the taskbar docked somewhere else? Like at the top of the screen, or one of the sides?

It shouldn't be hard, since I figure all I have to do is find out *where* the taskbar is. Is it at the bottom, the top, or one of the sides.  But I can't find any documentation anywhere, that explains how to get the location of the taskbar.

- Sean
0
Comment
Question by:headzoo
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
ShazbotOK earned 250 total points
ID: 18811841
Use the MouseEventArgs to display the location for where your notifyIcon was clicked on... you can then use that to extrapulate the location to how to display your "Sticky note" form

Example:

myNotifyIcon.MouseDown += new MouseEventHandler(myForm_MouseDown);

void myForm_MouseDown(object sender, MouseEventArgs e)
{
      int x = e.X;
      int y = e.Y;
      // now you can assign the location of your form from the X & Y locations of the mouse
     //  if the MouseDown event is too early then you can use the OnClick event to show this
}
0
 

Author Comment

by:headzoo
ID: 18833084
Hi ShazbotOK,
Well that's not the best solution.  One of these days I'm going to need to know the location of the task bar without using the mouse position. Suppose I want to have an alert message come up from the task bar?  When that day comes I'll be right back here asking the question again.

That being said you answered the question as I asked it, so I'll give you the points.
0
 
LVL 12

Expert Comment

by:ShazbotOK
ID: 18835562
If you want to display a notice to the user then use this you could also do it to capture an onclick event - this function implicitly knows the location of the taskbar's system tray:

void myBalloonFunc()
        {
                MyNotifyIcon.BalloonTipClicked += new EventHandler(MyApp_BalloonTipClicked);
                MyNotifyIcon.ShowBalloonTip(3500,"Show My Notification", "BlahBlah",ToolTipIcon.Info)
        }

void MyApp_BalloonTipClicked(object sender, EventArgs e)
        {
                throw new Exception("The method or operation is not implemented.");
        }
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question