winform 為圖片添加當(dāng)月的日歷并設(shè)為壁紙,可以手動(dòng)設(shè)置壁紙,也可以定時(shí)設(shè)置壁紙;最主要的特色是在圖片上生成當(dāng)前月的日歷信息。
定時(shí)自動(dòng)換壁紙需要自己手工制定壁紙文件夾,不是從網(wǎng)上自動(dòng)下載。
部分代碼:
/// <summary>
/// 定時(shí)自動(dòng)設(shè)置壁紙
/// </summary>
private void btnAutoSet_Click(object sender, EventArgs e)
{
string path = txtPicDir.Text;
if (!Directory.Exists(path))
{
MessageBox.Show("選擇的文件夾不存在");
return;
}
DirectoryInfo dirInfo = new DirectoryInfo(path);
picFiles = dirInfo.GetFiles("*.jpg");
if (picFiles.Length == 0)
{
MessageBox.Show("選擇的文件夾里面沒有圖片");
return;
}
if (btnAutoSet.Text == "開始")
{
timer1.Start();
btnAutoSet.Text = "停止";
lblStatus.Text = string.Format("定時(shí)自動(dòng)換壁紙中...");
}
else
{
timer1.Stop();
btnAutoSet.Text = "開始";
lblStatus.Text = "";
}
}
/// <summary>
/// 定時(shí)隨機(jī)設(shè)置壁紙
/// </summary>
private void timer_Tick(object sender, EventArgs e)
{
timer1.Interval = 1000 * 60 * (int)numericUpDown1.Value;
FileInfo[] files = picFiles;
if (files.Length > 0)
{
Random random = new Random();
int r = random.Next(1, files.Length);
Bitmap img = (Bitmap)Bitmap.FromFile(files[r].FullName);
pictureBox1.Image = img;
SetWallpaper(img);
}
}