notifyIcon簡易提醒
常常寫code寫到天荒地老才發現該下班了
做一個提醒自己該休息的的小工具
private void button1_Click(object sender, EventArgs e)
{
if( int.Parse(textBox1.Text.ToString()) > 23)
{
textBox1.Text = "23";
MessageBox.Show("系統幫你預設為24H");
}
if (int.Parse(textBox2.Text.ToString()) >59)
{
textBox2.Text = "59";
MessageBox.Show("系統幫你預設為59");
}
timer1.Interval = 3000;
label3.Text = "start";
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
DateTime MySpan1 = DateTime.Now;
string sec = MySpan1.Second.ToString();
string Minutes1 = MySpan1.Month.ToString();
string Days1 = MySpan1.Day.ToString();
string year = MySpan1.Year.ToString();
DateTime MyEndDate = new DateTime(int.Parse(year.ToString()), int.Parse(Minutes1.ToString()), int.Parse(Days1.ToString()), int.Parse(textBox1.Text.ToString()), int.Parse(textBox2.Text.ToString()), 00);
DateTime MyStartDate = DateTime.Now;
TimeSpan MySpan = MyEndDate.Subtract(MyStartDate);
string diffHour = Convert.ToString(MySpan.Hours);
string diffMin = Convert.ToString(MySpan.Minutes);
string diffSec = Convert.ToString(MySpan.Seconds);
int hour = int.Parse(diffHour);
int min = int.Parse(diffMin);
if (min < 5 & hour == 0)
{
notifyIcon1.BalloonTipText = "距離下班打卡還有 " + diffHour + " 時 " + diffMin + " 分 " + diffSec + " 秒 ";
notifyIcon1.BalloonTipTitle = "系統提醒";
notifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
notifyIcon1.ShowBalloonTip(3000);
}
}
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.notifyIcon1.Visible = true;
this.Hide();
}
else
{
this.notifyIcon1.Visible = false;
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
private void 打開ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
private void contextMenuStrip1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
this.Activate();
this.notifyIcon1.Visible = false;
this.ShowInTaskbar = true;
}
}
private void Form1_Load(object sender, EventArgs e)
{
notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
this.notifyIcon1.Icon = new Icon("./Q.ico");
}
private void 結束ToolStripMenuItem_Click(object sender, EventArgs e)
{
notifyIcon1.Visible = false;
this.Close();
Application.Exit();
}
private void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
{
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
timer1.Interval = 1000*60*60;
}
private void toolStripMenuItem3_Click(object sender, EventArgs e)
{
timer1.Interval = 1000 * 60 * 60*4;
}
private void toolStripMenuItem4_Click(object sender, EventArgs e)
{
timer1.Interval = 1000 * 60 * 60 * 12;
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar != '.')
{
e.Handled = true;
}
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar != '.')
{
e.Handled = true;
}
}
http://www.dotblogs.com.tw/chou/archive/2009/02/25/7284.aspx
http://www.dotblogs.com.tw/jimmyyu/archive/2009/09/21/10733.aspx
http://www.dotblogs.com.tw/yc421206/archive/2010/10/15/18370.aspx
大家一起加入blogads 賺零用錢!!