How can I remind myself of everything in my life?






4.69/5 (21 votes)
Don't forget to use Reminder v1.0 to remind everything.
- Download source code - 409 KB (with Lang option)
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.
- 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. - Warning with sound or without sound.
- You can choose Windows sounds for warning or custom songs (.mp3).
- 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. - And the app is now available with a Turkish or English interface.
Here is a list of WarnSounds:
With Sound.PLay()
:
With MCI Play command string:
Using the code
My main Form1.cs is formed of these parts:
- Variables
- Functions
For saving 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 four kinds of warnings to the user if something goes 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 the RTB so its 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;
}
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.
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.
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:
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 "";
}
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.
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;
}
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.
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.
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;
}
This is very easy. Windows keeps sounds in "C:\Windows\Media". We will just 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;
}
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.
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.
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 :)