Click here to Skip to main content
15,867,851 members
Articles / General Programming / File

How can I remind myself of everything in my life?

Rate me:
Please Sign up or sign in to vote.
4.69/5 (25 votes)
13 May 2011CPOL3 min read 44.3K   2.8K   43   17
Don't forget to use Reminder v1.0 to remind everything.

Interface.jpg

Introduction

I usually forget about my home work, my exams, my jobs :/. So I decided to write an application to remind me of these. Almost all of you use your computers for hours every day. The computer is harmful for all of our brains if used for a long time. With this application, we won't forget our to-dos. I will also explain parts of the code for this application.

Features

  • When you save a note, Reminder v1.0 saves it to File->Show Note ToolStripMenu for easy access. On every startup of Reminder v1.0, you can see these notes like in Office Word.
  • FeatureLikeWord.jpg

  • You can use your saved notes or write a new note for a TIMEDWARN. It chooses a note for you. TIMEDWARN is a warning message for which you can set the time and date.
  • FeatureTimedWarnAndCancelIT.jpg

  • Warning with sound or without sound.
  • FeatureTimedWarnWithSoundOrWithoutSound.jpg

  • You can choose Windows sounds for warning or custom songs (.mp3).
  • Here is a list of WarnSounds:

    FeatureWarnWindowsSounds.jpg

    FeatureWarnCustomSounds.jpg

  • When you hover over Windows sounds or custom songs with mouse, you will be able to listen to them. This is implemented with Sound.Play() or the MCI API.
  • With Sound.PLay():

    FeatureMouseOverSoundAndListen_.jpg

    With MCI Play command string:

    FeatureMouseOverCustomSoundAndListen_.jpg

  • And the app is now available with a Turkish or English interface.

Using the code

My main Form1.cs is formed of these parts:

  • Variables
  • Functions
  • For saving notes to menu:

    C#
    private void SaveNoteToMenu(string text)
    {
        newnote = new ToolStripMenuItem(text);
        newnote.Text = text;
        newnote.Click += new EventHandler(Item_Click);
        newnote.CheckedChanged += new EventHandler(Checked_Changed);
        newnote.CheckOnClick = true;
        showNoteToolStripMenuItem.DropDown.Items.Add(newnote);
    }
    
    private void TakeNotesToMenu()
    {
        string[] Files = Directory.GetFiles(SavePath);
        foreach (string file in Files)
        {
            FileInfo fileInfo = new FileInfo(file);
            if (fileInfo.Extension==".note")
                SaveNoteToMenu(fileInfo.Name);
        }
    }

    Check IsRTBStable: This function helps you to control RTB. I have four kinds of warnings to the user if something goes wrong. These are:

    C#
    string FirstRTBTEXT = "Write Your Note ..";
    string NameWarn = "First Give A Name Yo Your Note...";
    string notewarn = "FIRST WRITE SOMETHING";
    string NoNote = "There is No Note To Show";

    Then I should control the RTB so its text should not be these warnings.

    C#
    private bool IsRichTextBoxStable()
    {
        if (richNote.Text != FirstRTBTEXT 
            && richNote.Text != null && richNote.Text != notewarn 
            && richNote.Text!=NameWarn && richNote.Text!=NoNote)
            return true;
        else 
            return false;
    }
  • Form functions
  • On Form load, I check if the time is WarnTime. Is there a TIMEDWARN? Are notes Warned? Are there custom sounds? Get Windows sounds. I use four main if statements for these.

  • Component functions
  • Here is the ToolStripMenuItem's Click event:

    I should check on click of the CustomSong menu or on ShowNote menu or Warn Sounds menu, but Sounds menu would be different from Notes menu. We can check this with the sender object and a few if statements.

    C#
    private void Item_Click(object sender, EventArgs e)
    {
        if (sender is ToolStripMenuItem)  //Check On Click.
        {
            foreach (ToolStripMenuItem item in 
                    (((ToolStripMenuItem)sender).GetCurrentParent().Items))
            {
                if (item == sender)
                {
                    item.Checked = true;
                    clicked = true;
                    if (sender.ToString().Contains(".note"))
                    // If One Of Notes Clicked Then Show it
                    {
                        txtNoteName.Text = item.Text;
                        richNote.ResetText();
                        richNote.Text = functions.ShowNote(SavePath + "//" + 
                                                           txtNoteName.Text);
                    }
                    else if (sender.ToString().Contains(".wav"))
                    //If Sound selected Get it
                    {
                        WarnSoundWAV = sender.ToString();
                        soundselected = true;
                        CustomSoundSelected = false;
                        functions.PlayStopSound(sender.ToString(), false);
                        foreach (ToolStripMenuItem snd in 
                                    listToolStripMenuItem.DropDown.Items)
                            snd.Checked = false;
                    }
                    else  //If Mp3 Or Something Selected Get it
                    {
                        WarnCustomSound = sender.ToString();
                        CustomSoundSelected = true;
                        soundselected = false;
                        functions.StopSound();
                        foreach (ToolStripMenuItem snd in 
                                     warnSoundsToolStripMenuItem.DropDown.Items)
                            snd.Checked = false;
                    }
                }
                if ((item != null) && (item != sender))
                    item.Checked = false;
            }
        }    
    }

The OtherFunctions.cs class is formed of four parts:

  • DateTimeFunction:
  • All list of DateTime specialized string formats:

    http://msdn.microsoft.com/en-us/library/az4se3k1.aspx. Refer to MSDN. Or see the list here:

    C#
    String.Format("{0:t}", dt);  // "4:05 PM"                           ShortTime 
    String.Format("{0:d}", dt);  // "3/9/2008"                          ShortDate
    String.Format("{0:T}", dt);  // "4:05:07 PM"                        LongTime
    String.Format("{0:D}", dt);  // "Sunday, March 09, 2008"            LongDate
    String.Format("{0:f}", dt);  // "Sunday, March 09, 2008 4:05 PM"    LongDate+ShortTime
    String.Format("{0:F}", dt);  // "Sunday, March 09, 2008 4:05:07 PM" FullDateTime
    String.Format("{0:g}", dt);  // "3/9/2008 4:05 PM"                  ShortDate+ShortTime
    String.Format("{0:G}", dt);  // "3/9/2008 4:05:07 PM"               ShortDate+LongTime
    String.Format("{0:m}", dt);  // "March 09"                          MonthDay
    String.Format("{0:y}", dt);  // "March, 2008"                       YearMonth
    String.Format("{0:r}", dt);  // "Sun, 09 Mar 2008 16:05:07 GMT"     RFC1123
    String.Format("{0:s}", dt);  // "2008-03-09T16:05:07"               SortableDateTime
    String.Format("{0:u}", dt);  // "2008-03-09 16:05:07Z"              
                                 //  UniversalSortableDateTime
    C#
    public string GetDateTime(string DateOrClock)
    {
        DateTime dt = DateTime.Now;
        if (DateOrClock == "Date")
            return String.Format("{0:D}", dt); // Long date day, month dd, yyyy
        else if (DateOrClock == "Clock")
            return String.Format("{0:T}", dt); // Long time hh:mm:ss AM/PM
        else if (DateOrClock == "DateAndClock")
            return String.Format("{0:f}", dt);
            // Full date/short time day, month dd, yyyy hh:mm
        else
            return "";
    }
  • Note functions:
  • StreamWriter and StreamReader help us write or read from a stream like text files. For more info, please refer to MSDN: http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx.

    C#
    public void SaveNote(string path, RichTextBox rtb)
    {
        StreamWriter sw = new StreamWriter(path);
        for (int i = 0; i < rtb.Lines.Length; i++)
            sw.WriteLine(rtb.Lines[i]);
        sw.Close();
    }
    public string ShowNote(string path)
    {
        string Note;
        StreamReader sr = new StreamReader(path);
        Note = sr.ReadToEnd();
        sr.Close();
        return Note;
    }
  • Warning functions:
  • SetStartup: Windows keeps all startup applications in Regedit "CurrentUser\SOFTWARE\Microsoft\Windows\CurrentVersion\Run". So we should set this with our application name and /autoRun command line.

    We use Checkstartup to check our OnStartup ToolStripMenuItem when application starts on form load event.

    C#
    public void SetStartup(bool start)
    {
        RegistryKey rk = Registry.CurrentUser.OpenSubKey(
                         "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        RegistryKey rkk = 
          Registry.CurrentUser.OpenSubKey("SOFTWARE\\Reminder v1.0\\Note", true);
        if (start)
        {
            rk.SetValue(Path.GetFileName(Application.ExecutablePath).Replace(".exe", ""), 
                        Application.ExecutablePath.ToString() + " /autoRun");
            rkk.SetValue("CheckStartup", 1);
        }
        else
        {
            rk.DeleteValue(Path.GetFileName(
               Application.ExecutablePath).Replace(".exe", ""), false);
            rkk.SetValue("CheckStartup", 0);
        }
    }

    IsWarnTime: When user sets a TIMEDWARN, Reminder v1.0 writes a note to Registry, then with a timer, every second it should control the warnings. Let's get the Registry keys.

    C#
    public bool IsWarnTime()
    {
        RegistryKey rk = 
          Registry.CurrentUser.OpenSubKey("SOFTWARE\\Reminder v1.0\\Note", true);
        DateTime dt = DateTime.Now;
        string[] DateParts = rk.GetValue("TIME").ToString().Split('.');
        if (dt.ToLongDateString() == 
              DateParts[0] && dt.ToLongTimeString() == DateParts[1] + 
              ":" + DateParts[2] + ":" + DateParts[3])
        {
            //Set warned
            rk.SetValue("IsWarned", 1);
            return true;
        }
        else
            return false;
    }
  • Get Windows sounds:
  • This is very easy. Windows keeps sounds in "C:\Windows\Media". We will just get them :)

    C#
    public ArrayList GetWindowsSounds()
    {
        string[] AllFiles = Directory.GetFiles("C:\\Windows\\Media");
        ArrayList Sounds = new ArrayList();
        foreach (string file in AllFiles)
        {
            FileInfo fileInfo = new FileInfo(file);
            if (fileInfo.Extension == ".wav")
                Sounds.Add(fileInfo.FullName);
        }
        return Sounds;
    }

    Play or stop these sounds: The SoundPlayer class is used to play ".wav" files. It just plays Wav files and uses the System.Media reference.

    C#
    public void PlayStopSound(string SoundPath,bool PlayOrStop)
    {
        SoundPlayer Sound = new SoundPlayer(SoundPath);
        Sound.Load();
        if (PlayOrStop)
            Sound.PlayLooping();
        else
            Sound.Stop();
    }

    Use MCI to play songs: If you really want to learn about MCI, see my other article, or start from this website: http://msdn.microsoft.com/en-us/library/aa733658(v=vs.60).aspx.

    C#
    public void OpenFileToPlay(string filename)
    {
        string Pcommand = "open \"" + filename+ "\" type mpegvideo alias MediaFile";
        mciSendString(Pcommand, null, 0, IntPtr.Zero);
        Play(true);
    }
    public void Play(bool loop)
    {
        string Pcommand = "play MediaFile";
        if (loop)
            Pcommand += " REPEAT";
        mciSendString(Pcommand, null, 0, IntPtr.Zero);
    }
    public void StopSound()
    {
        string Pcommand = "close MediaFile";
        mciSendString(Pcommand, null, 0, IntPtr.Zero);
    }  //MCI has three main Command String (Open,Play,Stop).I just used them.
    //For MCI add this to your line which class name is there.
    [DllImport("winmm.dll")]
    private static extern long mciSendString(string strCommand, StringBuilder strReturn,
            int iReturnLength, IntPtr hwndCallback);

And that's all. This is very simple way to implement a reminder. You can improve this small application in many ways. Don't forget the people who you love and who love you.

History

I am new at writing articles. :) Please support me to in doing this because I like it. And I believe I can do it better on every article. Thanks. Happy coding :)

License

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


Written By
Team Leader
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 3 Pin
FernandoUY3-Jul-12 13:44
professionalFernandoUY3-Jul-12 13:44 
GeneralRe: My vote of 3 Pin
SercanOzdemir15-Jul-12 22:31
SercanOzdemir15-Jul-12 22:31 
GeneralEmail? Pin
Dewey13-May-11 9:34
Dewey13-May-11 9:34 
GeneralRe: Email? Pin
SercanOzdemir13-May-11 9:42
SercanOzdemir13-May-11 9:42 
Hmm difficult but good idea i'll evaluate it.For now iam working Reminder v2.0 With Voice support so you can record your voice and listen it on warn time.Thanks.
GeneralRe: Email? Pin
SercanOzdemir4-Jul-11 3:42
SercanOzdemir4-Jul-11 3:42 
GeneralMy vote of 5 Pin
betterwy9-May-11 21:21
betterwy9-May-11 21:21 
GeneralRe: My vote of 5 Pin
SercanOzdemir9-May-11 23:25
SercanOzdemir9-May-11 23:25 
GeneralMy vote of 5 Pin
Pritesh Aryan9-May-11 0:27
Pritesh Aryan9-May-11 0:27 
GeneralRe: My vote of 5 Pin
SercanOzdemir9-May-11 0:30
SercanOzdemir9-May-11 0:30 
GeneralMy vote of 3 Pin
ambarishtv8-May-11 23:59
ambarishtv8-May-11 23:59 
GeneralRe: My vote of 3 Pin
SercanOzdemir9-May-11 0:29
SercanOzdemir9-May-11 0:29 
GeneralRe: My vote of 3 Pin
Ed Nutting9-May-11 7:00
Ed Nutting9-May-11 7:00 
GeneralRe: My vote of 3 [modified] Pin
SercanOzdemir9-May-11 11:05
SercanOzdemir9-May-11 11:05 
GeneralWhat is the added value in usage? Pin
JV99998-May-11 21:42
professionalJV99998-May-11 21:42 
GeneralRe: What is the added value in usage? Pin
SercanOzdemir9-May-11 0:27
SercanOzdemir9-May-11 0:27 
GeneralRe: What is the added value in usage? Pin
JV999910-May-11 22:22
professionalJV999910-May-11 22:22 
GeneralRe: What is the added value in usage? Pin
SercanOzdemir11-May-11 0:32
SercanOzdemir11-May-11 0:32 

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.