NotePad.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using CCWin;
  3. using System.Drawing;
  4. using NotePad.Properties;
  5. using System.Windows.Forms;
  6. using System.Drawing.Imaging;
  7. using NotePad.Helper;
  8. using System.IO;
  9. using CCWin.SkinControl;
  10. using CCWin.SkinClass;
  11. namespace NotePad
  12. {
  13. public partial class NotePadForm : CCSkinMain
  14. {
  15. //图片的张数
  16. static int ImageCount = 15;
  17. //存放图片对象
  18. object[] BackImage = new object[ImageCount];
  19. //当前展示的图片的索引
  20. int ImageIndex = 0;
  21. //保存的子文件夹
  22. public static string Folder = @"Note\";
  23. public NotePadForm()
  24. {
  25. InitializeComponent();
  26. this.StartPosition = FormStartPosition.CenterScreen;
  27. NotePadTextArea.Font = (Font)Settings.Default["LastFont"];
  28. NotePadTextArea.ForeColor = (Color)Settings.Default["LastFontColor"];
  29. }
  30. private void NotePad_Load(object sender, EventArgs e)
  31. {
  32. BackImage[0] = Resources.psb;
  33. BackImage[1] = Resources.psb__5_;
  34. BackImage[2] = Resources.psb__1_;
  35. BackImage[3] = Resources.psb__3_;
  36. BackImage[4] = Resources._3_校园;
  37. BackImage[5] = Resources.IMG_2478;
  38. BackImage[6] = Resources.IMG_2576;
  39. BackImage[7] = Resources.IMG_3056;
  40. BackImage[8] = Resources.IMG_2439;
  41. BackImage[9] = Resources.image4;
  42. BackImage[10] = Resources.image1;
  43. BackImage[11] = Resources.image2;
  44. BackImage[12] = Resources._2_校园;
  45. BackImage[13] = Resources._1_考试作业校园;
  46. BackImage[14] = Resources.psb__4_;
  47. GetNoteList();
  48. //初始化背景图片
  49. BackgroundImage = TransparentImage((Bitmap)BackImage[ImageIndex], (float)0.2);
  50. ImageIndex = ImageIndex + 1;
  51. //计时器刷新图片
  52. BackImageTimer.Interval = 5 * 1000;
  53. BackImageTimer.Tick += ChangeBackGroundImage;
  54. BackImageTimer.Start();
  55. //播放音乐
  56. MusicPlayer.URL = Application.StartupPath + @"\人武训练的日子.mp3";
  57. MusicPlayer.Ctlcontrols.play();
  58. }
  59. /// <summary>
  60. /// 切换背景图片
  61. /// </summary>
  62. /// <param name="sender"></param>
  63. /// <param name="e"></param>
  64. private void ChangeBackGroundImage(object sender, EventArgs e)
  65. {
  66. Bitmap bitmap = (Bitmap)BackImage[ImageIndex];
  67. BackgroundImage = TransparentImage(bitmap, (float)0.2);
  68. ImageIndex = ImageIndex + 1;
  69. if (ImageIndex == ImageCount )
  70. ImageIndex = 0;
  71. }
  72. /// <summary>
  73. /// 实现图片渐变
  74. /// </summary>
  75. /// <param name="srcImage"></param>
  76. /// <param name="opacity"></param>
  77. /// <returns></returns>
  78. private Image TransparentImage(Image srcImage, float opacity)
  79. {
  80. float[][] nArray ={ new float[] {1, 0, 0, 0, 0},
  81. new float[] {0, 1, 0, 0, 0},
  82. new float[] {0, 0, 1, 0, 0},
  83. new float[] {0, 0, 0, opacity, 0},
  84. new float[] {0, 0, 0, 0, 1}};
  85. ColorMatrix matrix = new ColorMatrix(nArray);
  86. ImageAttributes attributes = new ImageAttributes();
  87. attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
  88. Bitmap resultImage = new Bitmap(srcImage.Width, srcImage.Height);
  89. Graphics g = Graphics.FromImage(resultImage);
  90. g.DrawImage(srcImage, new Rectangle(0, 0, srcImage.Width, srcImage.Height), 0, 0, srcImage.Width, srcImage.Height, GraphicsUnit.Pixel, attributes);
  91. return resultImage;
  92. }
  93. private void ColorPicker_Click(object sender, EventArgs e)
  94. {
  95. ColorDialog ColorForm = new ColorDialog();
  96. if (ColorForm.ShowDialog() == DialogResult.OK)
  97. {
  98. NotePadTextArea.SelectionColor = ColorForm.Color;
  99. Settings.Default["LastFontColor"] = ColorForm.Color;
  100. Settings.Default.Save();
  101. }
  102. }
  103. private void FontPicker_Click(object sender, EventArgs e)
  104. {
  105. FontDialog Font = new FontDialog();
  106. if (Font.ShowDialog() == DialogResult.OK)
  107. {
  108. NotePadTextArea.Font = Font.Font;
  109. Settings.Default["LastFont"] = Font.Font;
  110. Settings.Default.Save();
  111. }
  112. }
  113. private void Save_Click(object sender, EventArgs e)
  114. {
  115. WriteNote.Write(NotePadTextArea.Rtf, NoteList.SelectedIndex >= 0 ? NoteList.Items[NoteList.SelectedIndex].Text : "");
  116. GetNoteList();
  117. }
  118. private void NoteList_SelectedIndexChanged(object sender, EventArgs e)
  119. {
  120. NotePadTextArea.Clear();
  121. string FileName = Folder + NoteList.Items[NoteList.SelectedIndex].Text + ".txt";
  122. NotePadTextArea.Rtf = File.ReadAllText(FileName);
  123. LastWriteTime.Text = File.GetLastWriteTime(FileName).ToString();
  124. }
  125. private void GetNoteList()
  126. {
  127. NoteList.Items.Clear();
  128. //读取记录文件
  129. DirectoryInfo theFolder = new DirectoryInfo(Folder);
  130. foreach (FileInfo NextFile in theFolder.GetFiles())
  131. {
  132. SkinListBoxItem item = new SkinListBoxItem(NextFile.Name.Remove(NextFile.Name.Length - 4));
  133. this.NoteList.Items.Add(item);
  134. }
  135. }
  136. private void GetNoteList(string NoteDate)
  137. {
  138. NoteList.Items.Clear();
  139. //读取记录文件
  140. DirectoryInfo theFolder = new DirectoryInfo(Folder);
  141. foreach (FileInfo NextFile in theFolder.GetFiles())
  142. {
  143. if (NextFile.Name.Contains(NoteDate))
  144. {
  145. SkinListBoxItem item = new SkinListBoxItem(NextFile.Name.Remove(NextFile.Name.Length - 4));
  146. this.NoteList.Items.Add(item);
  147. }
  148. }
  149. }
  150. private void NoteTimerPicker_ValueChanged(object sender, EventArgs e)
  151. {
  152. NoteTimerPicker.Format = DateTimePickerFormat.Custom;
  153. GetNoteList(NoteTimerPicker.Text.ToString("yyyy-MM-dd"));
  154. }
  155. }
  156. }