Click here to Skip to main content
13,895,744 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


121 bookmarked
Posted 6 Jan 2010
Licenced CPOL

Windows 7: Taskbar Extension in Event in Time Application

, 12 Jan 2010
Rate this:
Please Sign up or sign in to vote.
Big idea with simple implementation (you use it daily)


Because exams are at the door and for businessman events, I made this program to manage events with alarm that you choose from your computer :), and I use the features of Windows 7 in Taskbar. I love it, this shows the time left for the event.
The two buttons show time left for (next event, previous event) without opening the program.

When time left is 0,the program makes an alarm and shows the notes, then the event is deleted.

The green win_taskbar: means the event left time is more.

The yellow win_taskbar: means the event left time is less.

The red one: means the alarm will appear any time.


Before explaining my application, I will explain how to use this technology in your application very easily :).
The technology: Taskbar Extension.
How??? By some steps!

  1. Add these references to your application (Microsoft.WindowsAPICodePack, Microsoft.WindowsAPICodePack.Shell)
  2. Use these namespaces in your application
    (using Microsoft.WindowsAPICodePack.Shell; <br />using Microsoft.WindowsAPICodePack.Taskbar;)
    And you will find them in file behind the Execution file.
  3. Declare these variables at the top of your application before constructor of the form;
    private TaskbarManager win_taskbar = TaskbarManager.Instance;<br />private ThumbnailToolbarButton button1;<br />private ThumbnailToolbarButton button2;
  4. In the event of shown form, write this:
Button1 = new ThumbnailToolbarButton(Properties.Resources.nextArrow, "Next Event");
Button1.Click += new EventHandler<thumbnailbuttonclickedeventargs>(relatedbutton2_Click);
Button2 = new ThumbnailToolbarButton(Properties.Resources.prevArrow, "Previous Event");
Button2.Click += new EventHandler<thumbnailbuttonclickedeventargs>(relatedbutton2_Click);
TaskbarManager.Instance.ThumbnailToolbars.AddButtons(this.Handle, Button1,Button2);

I make a new instance of the buttons shown in Windows taskbar, then I relate these buttons with event click of buttons on the form to make the same functionality.
Then I add them to the taskbar. And to use loading in Windows taskbar, just do this:

win_taskbar.SetProgressValue(current Value,Maximmum value)

Finish :).

Using the Code

The class holds all data for the events and can compare it with another class, then make inheritance from the interface “IComparable<task>”, to let me make comparison, and make “public static list” to hold all tasks and let me use it from everywhere in my application.

Now go to the code:

[Serializable]//for load and save events into file
   public class Task:IComparable<Task>
       public static List<Task> CurrentQueue;
       public string Name;
       public DateTime Time;
       public string Notes;
       public DateTime now;
       public Task(string name,DateTime time,string notes)
           Name = name;
           Time = time;
           Notes = notes;
           now = DateTime.Now;
       public Task(string name, DateTime time)
           : this(name, time, "")
       { }
       public Task(string name)
           Name = name;
       public int CompareTo(Task other)
           return Time.CompareTo(other.Time);

Now in the "Main form":

In this section, I will explain the main form “Class Events”: In the beginning of the class, I define a list of values to hold all total minutes left for your task, and make instance from taskbar and two buttons for taskbar. In the load of the form, I make a new instance of list of tasks and call function open() to load all tasks from the file and store it in this list. Then the function LoadDataGrid() to clear the recent data in grid and fill it with the tasks that I load it from the file. The function Save() to save all current events + new events when I closed the application. And button1 for calling function LoadDataGrid() + storing the difference in time between (time now and the task time) in value list + deleting the tasks that time has gone. Timer1 is to call form of alarm and refresh value list by calling button1. combobox holds values of value list and makes progressbar and Windows taskbar run. In the event shown of the main form, I initialize the two buttons in the taskbar and relate it with two buttons in main form that make the next event and the previous event.

public partial class Events : Form
        List<int> values = new List<int>();
        private TaskbarManager win_taskbar = TaskbarManager.Instance;
		private int steps=0;
        private ThumbnailToolbarButton Nexttask;
        private ThumbnailToolbarButton Previoustask;
		public string filename;
        public Events()
        private void Events_Load(object sender, EventArgs e)
			steps = 0;
            Task.CurrentQueue=new List<task>();
	//to open file and read all events from it and put it in list of events
        private static void Open()
            Stream file = new FileStream("data.bin", FileMode.Open, FileAccess.Read);
            IFormatter formatter = new BinaryFormatter();
            Task.CurrentQueue = (List<task>)formatter.Deserialize(file);
		//load events in the data grid
        public void LoadDataGrid()
             for (int i = 0; i < Task.CurrentQueue.Count; i++)
                if (Task.CurrentQueue[i].Time > DateTime.Now)
			Task.CurrentQueue[i].Time, Task.CurrentQueue[i].Notes);
	//Save events in file when the program close
        private static void Save()
            // to serialize an object of any serializable class
            IFormatter formatter = new BinaryFormatter();
            Stream file = new FileStream("data.bin", FileMode.Create, FileAccess.Write);
            formatter.Serialize(file, Task.CurrentQueue);
        //the refresh button for load the time left in minutes to 
        //a new list and sort is Asc.
        //and delete the event that time has been gone.
        public void button1_Click(object sender, EventArgs e)
            for (int i = 0; i < Task.CurrentQueue.Count; i++)
                TimeSpan temp = Task.CurrentQueue[i].Time-DateTime.Now;
				if (temp.TotalMinutes > 0)
            for (int i = 0; i < values.Count; i++)
			if (this.cmbtimes.Items.Count > steps)
				this.cmbtimes.SelectedIndex = steps;
			else if (this.cmbtimes.Items.Count != 0)
				this.cmbtimes.SelectedIndex = steps = 0;
				this.cmbtimes.Text = "";
        //timer to check the time for event and make the alarm
        private void timer1_Tick(object sender, EventArgs e)
            for (int i = 0; i < Task.CurrentQueue.Count; i++)
                if (Task.CurrentQueue[i].Time >= 
		DateTime.Now&&Task.CurrentQueue[i].Time< frmalarm=""new"" dif=""(int)t.TotalMinutes;"" progressbar1.value=""(int)Math.Ceiling((DateTime.Now-Task.CurrentQueue[index].now).TotalMinutes);"" progressbar1.maximum=""(int)Math.Ceiling(t.TotalMinutes);"" t=""Task.CurrentQueue[index].Time"" index=""cmbtimes.SelectedIndex;"" frmaddevent=""new"" this.opacity=""0;"" frmalarm.txtnotes.text=""Task.CurrentQueue[i].Notes;"" frmalarm.visible=""true;"" /> (dif * 3 / 4))
            if (progressBar1.Value > (dif * 9 / 10))
		//make Two button in windows taskbar
		//one for next event
		//other for previous event
		private void Events_Shown(object sender, EventArgs e)
			Nexttask = new ThumbnailToolbarButton
				(Properties.Resources.nextArrow, "Next Event");
			Nexttask.Click += new EventHandler
			Previoustask = new ThumbnailToolbarButton
				(Properties.Resources.prevArrow, "Previous Event");
			Previoustask.Click += new EventHandler
				(this.Handle, Previoustask,Nexttask);
			button1_Click(null, null);
		private void btnNext_Click(object sender, EventArgs e)
			button1_Click(null, null);
		private void btnPrevious_Click(object sender, EventArgs e)
			button1_Click(null, null);
		//choose file for alarm you want to hear *.wav
		private void chooseFileForAlarmToolStripMenuItem_Click
					(object sender, EventArgs e)
			if (openFileDialog1.ShowDialog() == DialogResult.OK)
				filename = openFileDialog1.FileName;
		private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    }</ />

And now the alarm form: The alarm form receives the file from the main form and if not, I store the file :) for this case to use it by default, and play the alarm when I call the form. Then show the notes of the event.


public partial class alarm : Form
		Events form;
        public alarm(Events form)
			this.form = form;
		//this Section for playing audio file for the alarm
		#region sound
		("winmm.DLL", EntryPoint = "PlaySound", 
		SetLastError = true, CharSet = CharSet.Unicode, 
		ThrowOnUnmappableChar = true)]
        private static extern bool PlaySound(string szSound, 
		System.IntPtr hMod, PlaySoundFlags flags);

        public enum PlaySoundFlags : int
            SND_SYNC = 0x0000,
            SND_ASYNC = 0x0001, 
            SND_NODEFAULT = 0x0002, 
            SND_LOOP = 0x0008, 
            SND_NOSTOP = 0x0010,
            SND_NOWAIT = 0x00000000, 
            SND_FILENAME = 0x00020000, 
            SND_RESOURCE = 0x00040004 
		//Close button for Press Esc
		private void button1_Click(object sender, EventArgs e)
            Events frmevents = new Events();
			form.Opacity = 100;
			form.button1_Click(this, null);
		//recive audio file from opendialogfile 
		private void alarm_Load(object sender, EventArgs e)
			//if you don't choose :)
			if (form.filename == null)
				form.filename = "audio.wav";
			PlaySound(form.filename, new System.IntPtr(), 
		//Event to play audio file.
		void Sp_LoadCompleted(object sender, AsyncCompletedEventArgs e)

Points of Interest

My program is useful for students studying subjects in time, for developers doing tasks, and for businessman managing events. It shows in the taskbar. You can know if the event is coming without opening the program, and two buttons to show the next event and previous event in taskbar. I learnt how to work with Windows 7 features and I enjoy with it very much, and learnt Serializable to save classes in file and read it :).


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


About the Author

Ahmed Ibrahim Assaf
Software Developer (Senior) ITWorx Education
Egypt Egypt
Developing solution for multi-channel e-Business solutions in different business sectors with focus in Banking, Trading, Commerce, Government and services sectors.

Also Outsourcing @ Al Rajhi Bank in KSA,
(SMS Banking. Gateway System, IPhone & IPad App, Middleware)

Cross Platform (Hybrid) Mobile Application (iOS, Android, BlackBerry, WP8),
Using PhoneGap and Cordova.

Design Patterns, Problem Solving,
C/C++,C#, VB.Net,Asp.Net,Objective C, PhoneGap, Cordova, Xamarin
JavaScript, jQuery, jQueryMobile,CSS3, HTML5, Nodejs.
And Fetching Titanium, Backbone.js, Underscore.js, knockoutjs And Angularjs.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
onewarden2-Dec-12 5:00
memberonewarden2-Dec-12 5:00 
GeneralRe: My vote of 5 Pin
Ahmed Ibrahim Assaf2-Dec-12 5:22
professionalAhmed Ibrahim Assaf2-Dec-12 5:22 
QuestionAbout Sp_LoadCompleted EvenHandler Pin
onewarden7-Dec-12 4:39
memberonewarden7-Dec-12 4:39 
AnswerRe: About Sp_LoadCompleted EvenHandler Pin
Ahmed Ibrahim Assaf9-Dec-12 19:58
professionalAhmed Ibrahim Assaf9-Dec-12 19:58 
GeneralGreat Article. My vote of 5. Pin
The Manoj Kumar21-Oct-10 13:23
memberThe Manoj Kumar21-Oct-10 13:23 
GeneralRe: Great Article. My vote of 5. Pin
Ahmed Ibrahim Assaf23-Oct-10 19:11
professionalAhmed Ibrahim Assaf23-Oct-10 19:11 
GeneralGood one :) Pin
eng.3bdelr7man12-Jan-10 7:19
membereng.3bdelr7man12-Jan-10 7:19 
GeneralRe: Good one :) Pin
modymido_201112-Jan-10 7:26
membermodymido_201112-Jan-10 7:26 
GeneralRe: Good one :) Pin
eng_3essa12-Jan-10 7:59
membereng_3essa12-Jan-10 7:59 
GeneralRe: Good one :) Pin
Ahmed Ibrahim Assaf13-Jan-10 8:17
professionalAhmed Ibrahim Assaf13-Jan-10 8:17 
GeneralNext time use a translator Pin
Brett Nemec12-Jan-10 5:06
professionalBrett Nemec12-Jan-10 5:06 
GeneralRe: Next time use a translator Pin
Ahmed Ibrahim Assaf12-Jan-10 7:00
professionalAhmed Ibrahim Assaf12-Jan-10 7:00 
GeneralI update my Visual Studio 2008 Pin
hackcat9-Jan-10 3:54
memberhackcat9-Jan-10 3:54 
GeneralRe: I update my Visual Studio 2008 Pin
hackcat9-Jan-10 4:17
memberhackcat9-Jan-10 4:17 
GeneralRe: I update my Visual Studio 2008 Pin
Abhishek Sur9-Jan-10 7:02
professionalAbhishek Sur9-Jan-10 7:02 
GeneralRe: I update my Visual Studio 2008 Pin
hackcat9-Jan-10 13:37
memberhackcat9-Jan-10 13:37 
GeneralRe: I update my Visual Studio 2008 [modified] Pin
Ahmed Ibrahim Assaf9-Jan-10 14:56
professionalAhmed Ibrahim Assaf9-Jan-10 14:56 
GeneralRe: I update my Visual Studio 2008 Pin
hackcat9-Jan-10 23:22
memberhackcat9-Jan-10 23:22 
GeneralRe: I update my Visual Studio 2008 Pin
Ahmed Ibrahim Assaf10-Jan-10 8:22
professionalAhmed Ibrahim Assaf10-Jan-10 8:22 
GeneralGood software! [modified] Pin
hackcat9-Jan-10 3:36
memberhackcat9-Jan-10 3:36 
AnswerRe: Good software! Pin
Ahmed Ibrahim Assaf9-Jan-10 14:53
professionalAhmed Ibrahim Assaf9-Jan-10 14:53 

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
Web01 | 2.8.190306.1 | Last Updated 12 Jan 2010
Article Copyright 2010 by Ahmed Ibrahim Assaf
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid