using System; using CCWin; using System.Drawing; using NotePad.Properties; using System.Windows.Forms; using System.Drawing.Imaging; using NotePad.Helper; using System.IO; using CCWin.SkinControl; using CCWin.SkinClass; namespace NotePad { public partial class NotePadForm : CCSkinMain { //图片的张数 static int ImageCount = 15; //存放图片对象 object[] BackImage = new object[ImageCount]; //当前展示的图片的索引 int ImageIndex = 0; //保存的子文件夹 public static string Folder = @"Note\"; public NotePadForm() { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; NotePadTextArea.Font = (Font)Settings.Default["LastFont"]; NotePadTextArea.ForeColor = (Color)Settings.Default["LastFontColor"]; } private void NotePad_Load(object sender, EventArgs e) { BackImage[0] = Resources.psb; BackImage[1] = Resources.psb__5_; BackImage[2] = Resources.psb__1_; BackImage[3] = Resources.psb__3_; BackImage[4] = Resources._3_校园; BackImage[5] = Resources.IMG_2478; BackImage[6] = Resources.IMG_2576; BackImage[7] = Resources.IMG_3056; BackImage[8] = Resources.IMG_2439; BackImage[9] = Resources.image4; BackImage[10] = Resources.image1; BackImage[11] = Resources.image2; BackImage[12] = Resources._2_校园; BackImage[13] = Resources._1_考试作业校园; BackImage[14] = Resources.psb__4_; GetNoteList(); //初始化背景图片 BackgroundImage = TransparentImage((Bitmap)BackImage[ImageIndex], (float)0.2); ImageIndex = ImageIndex + 1; //计时器刷新图片 BackImageTimer.Interval = 5 * 1000; BackImageTimer.Tick += ChangeBackGroundImage; BackImageTimer.Start(); //播放音乐 MusicPlayer.URL = Application.StartupPath + @"\人武训练的日子.mp3"; MusicPlayer.Ctlcontrols.play(); } /// /// 切换背景图片 /// /// /// private void ChangeBackGroundImage(object sender, EventArgs e) { Bitmap bitmap = (Bitmap)BackImage[ImageIndex]; BackgroundImage = TransparentImage(bitmap, (float)0.2); ImageIndex = ImageIndex + 1; if (ImageIndex == ImageCount ) ImageIndex = 0; } /// /// 实现图片渐变 /// /// /// /// private Image TransparentImage(Image srcImage, float opacity) { float[][] nArray ={ new float[] {1, 0, 0, 0, 0}, new float[] {0, 1, 0, 0, 0}, new float[] {0, 0, 1, 0, 0}, new float[] {0, 0, 0, opacity, 0}, new float[] {0, 0, 0, 0, 1}}; ColorMatrix matrix = new ColorMatrix(nArray); ImageAttributes attributes = new ImageAttributes(); attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); Bitmap resultImage = new Bitmap(srcImage.Width, srcImage.Height); Graphics g = Graphics.FromImage(resultImage); g.DrawImage(srcImage, new Rectangle(0, 0, srcImage.Width, srcImage.Height), 0, 0, srcImage.Width, srcImage.Height, GraphicsUnit.Pixel, attributes); return resultImage; } private void ColorPicker_Click(object sender, EventArgs e) { ColorDialog ColorForm = new ColorDialog(); if (ColorForm.ShowDialog() == DialogResult.OK) { NotePadTextArea.SelectionColor = ColorForm.Color; Settings.Default["LastFontColor"] = ColorForm.Color; Settings.Default.Save(); } } private void FontPicker_Click(object sender, EventArgs e) { FontDialog Font = new FontDialog(); if (Font.ShowDialog() == DialogResult.OK) { NotePadTextArea.Font = Font.Font; Settings.Default["LastFont"] = Font.Font; Settings.Default.Save(); } } private void Save_Click(object sender, EventArgs e) { WriteNote.Write(NotePadTextArea.Rtf, NoteList.SelectedIndex >= 0 ? NoteList.Items[NoteList.SelectedIndex].Text : ""); GetNoteList(); } private void NoteList_SelectedIndexChanged(object sender, EventArgs e) { NotePadTextArea.Clear(); string FileName = Folder + NoteList.Items[NoteList.SelectedIndex].Text + ".txt"; NotePadTextArea.Rtf = File.ReadAllText(FileName); LastWriteTime.Text = File.GetLastWriteTime(FileName).ToString(); } private void GetNoteList() { NoteList.Items.Clear(); //读取记录文件 DirectoryInfo theFolder = new DirectoryInfo(Folder); foreach (FileInfo NextFile in theFolder.GetFiles()) { SkinListBoxItem item = new SkinListBoxItem(NextFile.Name.Remove(NextFile.Name.Length - 4)); this.NoteList.Items.Add(item); } } private void GetNoteList(string NoteDate) { NoteList.Items.Clear(); //读取记录文件 DirectoryInfo theFolder = new DirectoryInfo(Folder); foreach (FileInfo NextFile in theFolder.GetFiles()) { if (NextFile.Name.Contains(NoteDate)) { SkinListBoxItem item = new SkinListBoxItem(NextFile.Name.Remove(NextFile.Name.Length - 4)); this.NoteList.Items.Add(item); } } } private void NoteTimerPicker_ValueChanged(object sender, EventArgs e) { NoteTimerPicker.Format = DateTimePickerFormat.Custom; GetNoteList(NoteTimerPicker.Text.ToString("yyyy-MM-dd")); } } }