Interface.jpg

Introduction 

I usually forget my homeworks,my exams,my jobs :/. So I decided to write an application to remind these.Almost all of you use your computers for hours. Computer is harmful for all of our brains. But with this application we wont forget :)And also I dont want you to be confuse so I will explain code parts with easy expressions. 

Features  

-When you save your Note Reminder v1.0 saves it to it's File->Show Note ToolStripMenu for easy reaching.On every startup of Reminder v1.0 you can see these notes like Office Word.   

FeatureLikeWord.jpg 

-You can use your saved notes or write a new note for a TIMEDWARN. It chooses note for you.  TIMEDWARN is a warning message which you can set it's time and date.  

 FeatureTimedWarnAndCancelIT.jpg

-Warning with sound or without sound. 

FeatureTimedWarnWithSoundOrWithoutSound.jpg

-You can choose Windows sounds for WARNING or Custom songs(.mp3) 

WarnSounds -> 

FeatureWarnWindowsSounds.jpgFeatureWarnCustomSounds.jpg

-When you come over Windows sounds or custom songs with mouse you will listen them.With Sound.Play() or MCI  API:) 

With Sound.PLay() : 

FeatureMouseOverSoundAndListen_.jpg

With MCI Play Command String :  

FeatureMouseOverCustomSoundAndListen_.jpg

-And now with Turkish Or English Interface. 

Using the code  

My main Form1.cs is formed from 4 parts.

-Variables   

-Functions 

 For Save Notes to Menu :  

 

			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 4 kind of warnings to user if something is going wrong. These are :

  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 RTB it's Text should not be these warnings. 

  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

Especially on Form Load I check Is the time warntime ? , Is there a TIMEDWARN ?, Is Note have Warned ? , Is there custom sounds ? ,And Get Windows sounds. I used 4 main IF statement for them just examine codes with Browse Code.You'll see and understand what I mean. 

-Component Functions

-For Created ToolStripMenuItems Click Event :

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

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;
                }
            }    
        } 

And OtherFunctions.cs Class is formed from 4 parts too.

-DateTimeFunction  :

All List of  DateTime specialized string formats : 

http://msdn.microsoft.com/en-us/library/az4se3k1.aspx  Examine msdn. Or look at bottom.

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
 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 helps us Write or Read from a stream like Text files. For more info please look at msdn : http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx 

 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 are using Checkstartup to check our OnStartup ToolStripMenuItem when application starts on form load event.  

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);
            }
        } 

Check IsWarnTime ? :

When user sets a TIMEDWARN Reminder v1.0 writes note to Registry then with a timer every second it should control have the warning came.So lets get these RegistryKey. 

 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;
        } 

-And Warning Sounds Get Windows Sounds :

It's a very easy method just focus Windows keeps Sounds on "C:\Windows\Media" Lets get them :) 

 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;
        } 

PlayOrStop These Sounds :

SoundPlayer Class is using for to play ".wav" files.It just plays Wav files.And it uses System.Media Referance. 

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

Like Use MCI to Play Songs :

For MCI we can say so much thinks.So if you really want to learn something about MCI please examine my other article or start from this website http://msdn.microsoft.com/en-us/library/aa733658(v=vs.60).aspx

 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 remind something. Dont forget people who you love and who love you. You can improve this small application.  

History 

Iam new at writing articles. :) Please support me to do this because i like it.And i believe i can do it better on every article.Thanks.Happy Coding :) 

推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架