我如何提醒自己生活中的一切?






4.69/5 (21投票s)
不要忘记使用 Reminder v1.0 来提醒所有事情。
- 下载源代码 - 409 KB (带有语言选项)
引言
我经常忘记我的家庭作业、考试和工作 :/. 所以我决定编写一个应用程序来提醒我这些。 几乎你们所有人都每天使用电脑几个小时。长时间使用电脑对我们的大脑有害。 使用此应用程序,我们不会忘记我们的待办事项。 我还将解释此应用程序的部分代码。
特点
- 当您保存笔记时,Reminder v1.0 会将其保存到文件->显示笔记 ToolStripMenu 中,以便于访问。 每次启动 Reminder v1.0 时,您都可以像在 Office Word 中一样看到这些笔记。
- 您可以使用保存的笔记或为
TIMEDWARN
编写新笔记。它会为您选择一个笔记。TIMEDWARN
是一个警告消息,您可以设置时间和日期。 - 带声音或不带声音的警告。
- 您可以选择 Windows 声音作为警告或自定义歌曲 (.mp3)。
- 当您将鼠标悬停在 Windows 声音或自定义歌曲上时,您将能够收听它们。 这是使用
Sound.Play()
或 MCI API 实现的。 - 该应用程序现在提供土耳其语或英语界面。
这是 WarnSounds 的列表
使用 Sound.PLay()
使用 MCI Play 命令字符串
使用代码
我的主 Form1.cs 由以下部分组成
- 变量
- 函数
用于将笔记保存到菜单
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);
}
}
检查 IsRTBStable
:此函数可帮助您控制 RTB。 如果出现问题,我有四种类型的警告给用户。 这些是
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";
然后我应该控制 RTB,使其文本不应是这些警告。
private bool IsRichTextBoxStable()
{
if (richNote.Text != FirstRTBTEXT
&& richNote.Text != null && richNote.Text != notewarn
&& richNote.Text!=NameWarn && richNote.Text!=NoNote)
return true;
else
return false;
}
在窗体加载时,我检查时间是否为 WarnTime
。 有 TIMEDWARN
吗? 笔记是否被 Warned
? 有自定义声音吗? 获取 Windows 声音。 我使用四个主要的 if
语句来执行这些操作。
这是 ToolStripMenuItem
的 Click
事件
我应该检查 CustomSong 菜单的点击,或者 ShowNote 菜单或 Warn Sounds 菜单的点击,但是 Sounds 菜单将与 Notes 菜单不同。 我们可以使用 sender
对象和几个 if
语句来检查这一点。
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;
}
}
}
OtherFunctions.cs 类由四个部分组成
DateTimeFunction
:
所有 DateTime
专用字符串格式列表
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx. 请参阅 MSDN。 或在此处查看列表
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
和 StreamReader
帮助我们写入或读取来自流(如文本文件)的数据。 有关更多信息,请参阅 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 将所有启动应用程序保存在 Regedit "CurrentUser\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" 中。 因此,我们应该使用我们的应用程序名称和 /autoRun 命令行来设置此值。
当应用程序在窗体加载事件中启动时,我们使用 Checkstartup
来检查我们的 OnStartup ToolStripMenuItem
。
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
:当用户设置 TIMEDWARN
时,Reminder v1.0 会将一个注释写入注册表,然后通过一个计时器,每秒它都应该控制警告。 让我们获取注册表项。
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;
}
这非常容易。 Windows 将声音保存在 "C:\Windows\Media" 中。 我们将直接获取它们 :)
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;
}
播放或停止这些声音:SoundPlayer
类用于播放 ".wav" 文件。 它仅播放 Wav 文件并使用 System.Media
引用。
public void PlayStopSound(string SoundPath,bool PlayOrStop)
{
SoundPlayer Sound = new SoundPlayer(SoundPath);
Sound.Load();
if (PlayOrStop)
Sound.PlayLooping();
else
Sound.Stop();
}
使用 MCI 播放歌曲:如果您真的想了解 MCI,请参阅我的其他文章,或者从这个网站开始: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);
就这样了。 这是实现提醒的一种非常简单的方法。 您可以通过多种方式改进这个小应用程序。 不要忘记你爱的人和爱你的人。
历史
我刚开始写文章。 :) 请支持我这样做,因为我喜欢它。 而且我相信我可以在每篇文章中做得更好。 谢谢。 祝您编码愉快 :)