Click here to Skip to main content
13,794,579 members
Click here to Skip to main content
Add your own
alternative version


27 bookmarked
Posted 4 Mar 2008
Licenced CPOL

Persian Calendar with Tray Icon

, 12 Mar 2012
Rate this:
Please Sign up or sign in to vote.
A Persian calendar that shows a tray icon



In this article, I will teach you how to build a simple application that creates a tray icon and shows a simple menu. Also in this article, you'll learn how to hide the main form of your application. If you are Persian, you can find codes that convert the date of a system to Hejri Shamsi and show the date in a tray icon.In new version add many new feature including showing the calendar,scheduling tasks and also printing tasks.Please download the new version. 

Using the Code 

To create a program that shows a tray icon, you should add a notify icon control to your form from the toolbox. Notify icons have some properties:


Some important properties are:

  1. Icon: changes the icon that shows in a tray icon
  2. Visible: sets if the icon is shown or not
  3. ContextMenu: sets a menu for your tray icon
  4. Text: sets the tool tip of a tray icon

I set all of these properties in a constructor of form:

public Form1()
            /* some code there

            string s = strDay + " " + Convert.ToString(dd) + " " + 
                strMonth + " " + Convert.ToString(yy);
            s += "\n" + d1.ToLongDateString();
            notifyIcon1.Text = s;

            m_menu = new ContextMenu();
                new MenuItem("Exit", new System.EventHandler(Exit_Click)));
            notifyIcon1.ContextMenu = m_menu;
            notifyIcon1.Visible = true;

In this project, I want a to hide my main form. For this, I did the following:

  1. Set the ormWindowState property of the form to Minimized
  2. Set the Opacity property of the form to 0
  3. Set the ShowInTaskbar property to false
  4. Add an event handler for VisibleChanged and add the below code:
private void Form1_VisibleChanged(object sender, EventArgs e)
      this.Visible = false;

So, this program just shows a tray icon and the main form is not displayed. Therefore, for exiting from the program, I create a menu for the tray icon with an exit item. When the user clicks on the exit item, the program ends.

protected void Exit_Click(Object sender, System.EventArgs e)

My program changes the tray icon related the date in Hejri Shamsi. For doing this, I created 31 icons and added them to the resource of my project. I created an array of form icons.

Icon[] Icon_ar = new Icon[32];
Icon_ar[1] = global::mytray.Properties.Resources.icon1;
Icon_ar[2] = global::mytray.Properties.Resources.icon2;
Icon_ar[3] = global::mytray.Properties.Resources.icon3;
Icon_ar[4] = global::mytray.Properties.Resources.icon4;
Icon_ar[5] = global::mytray.Properties.Resources.icon5;
Icon_ar[6] = global::mytray.Properties.Resources.icon6;
Icon_ar[7] = global::mytray.Properties.Resources.icon7;
Icon_ar[8] = global::mytray.Properties.Resources.icon8;
Icon_ar[9] = global::mytray.Properties.Resources.icon9;
Icon_ar[10] = global::mytray.Properties.Resources.icon10;
Icon_ar[11] = global::mytray.Properties.Resources.icon11;
Icon_ar[12] = global::mytray.Properties.Resources.icon12;
Icon_ar[13] = global::mytray.Properties.Resources.icon13;
Icon_ar[14] = global::mytray.Properties.Resources.icon14;
Icon_ar[15] = global::mytray.Properties.Resources.icon15;
Icon_ar[16] = global::mytray.Properties.Resources.icon16;
Icon_ar[17] = global::mytray.Properties.Resources.icon17;
Icon_ar[18] = global::mytray.Properties.Resources.icon18;
Icon_ar[19] = global::mytray.Properties.Resources.icon19;
Icon_ar[20] = global::mytray.Properties.Resources.icon20;
Icon_ar[21] = global::mytray.Properties.Resources.icon21;
Icon_ar[22] = global::mytray.Properties.Resources.icon22;
Icon_ar[23] = global::mytray.Properties.Resources.icon23;
Icon_ar[24] = global::mytray.Properties.Resources.icon24;
Icon_ar[25] = global::mytray.Properties.Resources.icon25;
Icon_ar[26] = global::mytray.Properties.Resources.icon26;
Icon_ar[27] = global::mytray.Properties.Resources.icon27;
Icon_ar[28] = global::mytray.Properties.Resources.icon28;
Icon_ar[29] = global::mytray.Properties.Resources.icon29;
Icon_ar[30] = global::mytray.Properties.Resources.icon30;
Icon_ar[31] = global::mytray.Properties.Resources.icon31;

In the above code, I retrieve Icons from the resource of the assembly. Retrieving has the advantage that, at run time, your EXE files have icons inside and don't need external files.

notifyIcon1.Icon = Icon_ar[dd];


In this simple project, you can find the solution for the problems of creating tray icons, creating menus and retrieving icons from resources.

I hope this is useful.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

mohammad hajibegloo
Engineer neyshabur azad univeristy
Iran (Islamic Republic of) Iran (Islamic Republic of)
I had worked as programmer,project manager,web developer for more than 3 years, and have worked on programming personaly for more than 10 years.
I have worked in university as a teacher for 8 years.
my favorite langueges are : VC++,C#,ASP.NET,PHP

You may also be interested in...

Comments and Discussions

QuestionProblem with zip file Pin
Shadi Rahmani6-Nov-12 2:23
memberShadi Rahmani6-Nov-12 2:23 
AnswerRe: Problem with zip file Pin
mohammad hajibegloo15-Feb-13 1:00
membermohammad hajibegloo15-Feb-13 1:00 
Generalwe have already one but... Pin
taha bahraminezhad Jooneghani20-Mar-12 23:52
membertaha bahraminezhad Jooneghani20-Mar-12 23:52 
QuestionThanks my Professor Pin
mohammad zargarani12-Mar-12 20:20
membermohammad zargarani12-Mar-12 20:20 
AnswerRe: Thanks my Professor Pin
mohammad hajibegloo15-Mar-12 10:58
membermohammad hajibegloo15-Mar-12 10:58 
QuestionTannks for you Pin
svk6628-Jan-12 4:01
membersvk6628-Jan-12 4:01 
AnswerRe: Tannks for you Pin
mohammad hajibegloo28-Jan-12 4:32
membermohammad hajibegloo28-Jan-12 4:32 
QuestionThanks Pin
Member 81404728-Aug-11 19:05
memberMember 81404728-Aug-11 19:05 
Generalthanks Pin
deepshit8-Mar-10 20:52
memberdeepshit8-Mar-10 20:52 
GeneralRe: thanks Pin
mohammad hajibegloo24-Jul-10 5:46
membermohammad hajibegloo24-Jul-10 5:46 
GeneralMy vote of 2 Pin
DungVinh6-Sep-09 18:43
memberDungVinh6-Sep-09 18:43 
GeneralRe: My vote of 2 Pin
mohammad hajibegloo24-Jul-10 5:47
membermohammad hajibegloo24-Jul-10 5:47 
GeneralRe: My vote of 2 Pin
mohammad hajibegloo15-Mar-12 11:00
membermohammad hajibegloo15-Mar-12 11:00 
AnswerRe: My vote of 2 Pin
taha bahraminezhad Jooneghani20-Mar-12 23:54
membertaha bahraminezhad Jooneghani20-Mar-12 23:54 
Generalcalendar Pin
hamed.shokri13-May-09 23:39
memberhamed.shokri13-May-09 23:39 
GeneralRe: calendar Pin
mohammad hajibegloo24-Jul-10 5:47
membermohammad hajibegloo24-Jul-10 5:47 
GeneralSimple but wonderful ! Pin
rostamiani16-Dec-08 3:14
memberrostamiani16-Dec-08 3:14 
GeneralRe: Simple but wonderful ! Pin
mohammad hajibegloo24-Jul-10 5:48
membermohammad hajibegloo24-Jul-10 5:48 
GeneralGood work Pin
Mohammad Dayyan15-Sep-08 12:30
memberMohammad Dayyan15-Sep-08 12:30 
GeneralRe: Good work Pin
mohammad hajibegloo24-Jul-10 5:48
membermohammad hajibegloo24-Jul-10 5:48 
Newseyval Pin
sdfa12-Mar-08 0:47
membersdfa12-Mar-08 0:47 
GeneralRe: eyval Pin
mohammad hajibegloo24-Jul-10 5:48
membermohammad hajibegloo24-Jul-10 5:48 
Generalsalam Pin
m_s_rezaei11-Mar-08 19:45
memberm_s_rezaei11-Mar-08 19:45 
GeneralRe: salam Pin
mohammad hajibegloo24-Jul-10 5:49
membermohammad hajibegloo24-Jul-10 5:49 
GeneralPersianCalendar Pin
Mehdy Khoshrou5-Mar-08 5:00
memberMehdy Khoshrou5-Mar-08 5:00 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.181207.3 | Last Updated 12 Mar 2012
Article Copyright 2008 by mohammad hajibegloo
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid