发送邮件&Timer

发送邮件: 命名空间(using System.Net.Mail; using System.Net;)

SmtpClient sm = new SmtpClient("smtp.sina.cn");
MailAddress from = new MailAddress("18560812711@sina.cn");
MailAddress to = new MailAddress("928176983@qq.com");
MailMessage me = new MailMessage(from, to);
me.Subject = "啦啦阿拉!";
me.Body = "感谢你使用本系统,服务费免费!";
NetworkCredential cr = new NetworkCredential("18560812711@sina.cn", "hq1234561");
sm.Credentials = cr;
sm.Send(me);

Timer的应用:如按钮点击后倒计时

button1.Enabled = false;
timer1.Enabled = true;
}
int a = 10;
private void timer1_Tick(object sender, EventArgs e)
{
a--;
button1.Text = "倒计时" + a + "秒!";
if (a == 0)
{
button1.Text = "发送";
button1.Enabled = true;
timer1.Enabled = false;
}
}

动画效果:

private void button2_Click(object sender, EventArgs e)
{
timer2.Enabled = true;
}

private void timer2_Tick(object sender, EventArgs e)
{
int x = button2.Location.X;
int y = button2.Location.Y;
button2.Location = new Point(x+5, y);
if (x > 200)
{
timer2.Enabled = false;
}
}

posted on 2017-11-30 15:42  段了的弦  阅读(153)  评论(0编辑  收藏  举报