Click here to Skip to main content
12,623,511 members (31,553 online)
Click here to Skip to main content
Add your own
alternative version

Stats

127.8K views
3.8K downloads
130 bookmarked
Posted

NotifyIconChart

, 31 Aug 2002
Rate this:
Please Sign up or sign in to vote.
A .NET component that creates pie and bar charts in the system tray

Sample Image

Introduction

This component will help you to create a little chart in the System Tray. This is useful in applications like GetRight, which show progress of an operation (eg downloading). It can also show some system information (like CPU usage). NotifyIconChart provides three types of charts: single bar, two bars, and pie.

Using NotifyIconChart

First, add NotifyIconChart.cs to your project. The NotifyIconChart is placed in System.Windows.Forms namespace, so it won’t make any trouble with namespaces in your solution.

You have to add to your form class a System.Windows.Forms.NotifyIcon object. I would like to inherit NotifyIconChart from the NotifyIcon, but it’s sealed (you can’t inherit from the sealed class). So I decided that NotifyIconChart would have a member pointer to a NotifyIcon object.

In the form constructor or Load event, set the NotifyIconChart’s NotifyIconObject property:

private NotifyIconChart notifyChart = new NotifyIconChart();
NotifyIcon notifyIcon = new NotifyIcon();
notifyChart.NotifyIconObject = notifyIcon;

Now set values. There are two properties that you can use: Value1 and Value2. The first bar, single bar or the pie will be drawn using the first value. The Value2 is used only when drawing the second bar. The values take integers between 0 and 100.

notifyChart.Value1 = 75;
notifyChart.Value2 = 43;

How does it work?

The NotifyIconChart uses a NotifyIcon object, which is responsible for displaying the chart. It gets only System.Drawing.Icon. That mean that NotifyIconChart has to create the icon. The .Net framework uses GDI+ for drawing. The Graphics object can’t draw on an Icon, but it can draw on a Bitmap. The NotifyIconChart draws on a bitmap (size 16x16) bars or a pie. It uses Graphics’ functions FillRectangle and FillPie. At the end it convert the Bitmap to an Icon and pass it to the NotifyIcon object:

// Convert Bitmap to an Icon
Icon icon = Icon.FromHandle(bitmap.GetHicon());
notifyIcon.Icon = icon;

Changing type of the chart

As I said, there are three types of charts provided by NotifyIconChart: single bar, two bars, and pie. To change the type, just change the ChartType value:

notifyChart.ChartType = NotifyIconChart.ChartTypeEnum.singleBar; // Draw one only bar
notifyChart.ChartType = NotifyIconChart.ChartTypeEnum.twoBars; // Draw two bars
notifyChart.ChartType = NotifyIconChart.ChartTypeEnum.pie; // Draw pie chart

Colors

There are four properties that you can use to change colors:

Color1 and Color2 are responsible for the bars’ colors. The pie will be drawn using Color1.

FrameColor is responsible for frames around bars and pie.

BackgroundColor is the color of the background. NotifyIconChart draws rectangular background when it draws bars, and circular when it draws pie.

If you don’t want the NotifyIconChart to draw any of these element’s set it’s value to Color.Transparent.

notifyChart.FrameColor = Color.Black;
notifyChart.Color1 = Color.Yellow;

Conclusion

System Tray isn’t the best place for charts, because it is rather small. But sometimes chart can be very useful there. Thanks to GDI+ functions like anti-aliasing, even a pie chart looks great. If you want any other type of chart in your System Tray, just give me a sign.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Maciej Pirog
Web Developer
Poland Poland
I've been programming since I was really young. Started with HTML and Basic, looked at Pascal and Java, keen on Visual Basic and Visual C++, thinking about .NET and C#.

You may also be interested in...

Comments and Discussions

 
General16 bars one for each vertical row in the icon Pin
Member #277097710-Jan-07 7:01
memberMember #277097710-Jan-07 7:01 
GeneralnotifyIcon.Visible = true; Pin
ToothRobber9-Jan-07 5:14
memberToothRobber9-Jan-07 5:14 
GeneralTidying up Pin
Drew Noakes7-Apr-05 7:18
memberDrew Noakes7-Apr-05 7:18 
GeneralRe: Tidying up Pin
dzCepheus4-Sep-05 12:48
memberdzCepheus4-Sep-05 12:48 
GeneralNice Pin
ngna19-Sep-04 21:35
memberngna19-Sep-04 21:35 
GeneralRe: Nice Pin
Maciej Pirog1-Oct-04 8:51
memberMaciej Pirog1-Oct-04 8:51 
GeneralCopy cursor into Bitmap - C# Pin
jayakarthikeyan17-Jun-04 2:45
memberjayakarthikeyan17-Jun-04 2:45 
GeneralCopy cursor into Bitmap Pin
jayakarthikeyan17-Jun-04 2:40
memberjayakarthikeyan17-Jun-04 2:40 
GeneralThis is excellent! Pin
Cavaradossi21-Aug-03 1:44
memberCavaradossi21-Aug-03 1:44 
GeneralRe: This is excellent! Pin
Maciej Pirog21-Aug-03 3:36
memberMaciej Pirog21-Aug-03 3:36 
GeneralAlles klar Pin
lukasz stypka4-Mar-03 3:16
susslukasz stypka4-Mar-03 3:16 
GeneralUse composition to create NotifyIcon. Pin
Peter Rilling25-Jan-03 5:06
memberPeter Rilling25-Jan-03 5:06 
GeneralRe: Use composition to create NotifyIcon. Pin
Maciej Pirog2-Feb-03 0:37
memberMaciej Pirog2-Feb-03 0:37 
GeneralScrolling Chart like DuMeter Pin
Anonymous9-Nov-02 11:13
sussAnonymous9-Nov-02 11:13 
GeneralGetHicon - A general error occurred in GDI+ Pin
Ingram Leedy18-Oct-02 22:03
memberIngram Leedy18-Oct-02 22:03 
GeneralRe: GetHicon - A general error occurred in GDI+ Pin
Maciej Pirog19-Oct-02 6:42
memberMaciej Pirog19-Oct-02 6:42 
GeneralRe: GetHicon - A general error occurred in GDI+ Pin
NewtonTroy3-Nov-03 10:08
memberNewtonTroy3-Nov-03 10:08 
GeneralRe: GetHicon - A general error occurred in GDI+ Pin
mrblueguy11-Nov-03 1:14
membermrblueguy11-Nov-03 1:14 
GeneralRe: GetHicon - A general error occurred in GDI+ Pin
paragvt27-Jun-05 14:01
memberparagvt27-Jun-05 14:01 
GeneralRe: GetHicon - A general error occurred in GDI+ Pin
orumcektr2-Aug-06 5:26
memberorumcektr2-Aug-06 5:26 
GeneralNice! Pin
Tim Hodgson3-Sep-02 4:55
memberTim Hodgson3-Sep-02 4:55 
GeneralRe: Nice! Pin
Maciej Pirog3-Sep-02 8:26
memberMaciej Pirog3-Sep-02 8:26 
Generalcześć Pin
ARTUR PIRÓG18-Oct-03 3:12
sussARTUR PIRÓG18-Oct-03 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 1 Sep 2002
Article Copyright 2002 by Maciej Pirog
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid