• 简易备忘录


    目录

    一  设计原型效果

    二 后台源码


    一  设计原型效果

    勾选每个选项时,代表已经完成该项,程序会自动删除。

    二 后台源码

    1. using Newtonsoft.Json;
    2. namespace 简易备忘录
    3. {
    4. public partial class Form1 : Form
    5. {
    6. public Form1()
    7. {
    8. InitializeComponent();
    9. }
    10. private string NoteContentPath = Directory.GetCurrentDirectory() + "\\NoteContent.json";
    11. List<string> Notes = new List<string>();
    12. private void Note_SelectedIndexChanged(object sender, EventArgs e)
    13. {
    14. //移除已完成的事项
    15. for (int i = 0; i < this.Note.Items.Count; i++)
    16. {
    17. if (this.Note.GetItemChecked(i))
    18. {
    19. this.Note.Items.RemoveAt(i);
    20. Notes.RemoveAt(i);
    21. File.WriteAllText(NoteContentPath, JsonConvert.SerializeObject(Notes));
    22. }
    23. }
    24. }
    25. private void Add_Click(object sender, EventArgs e)
    26. {
    27. //弹出记事弹窗
    28. Info info = new Info();
    29. info.ShowDialog();
    30. if (info.IsOk)
    31. {
    32. Note.Items.Add(info.MyInfo);
    33. Notes.Add(info.MyInfo);
    34. File.WriteAllText(NoteContentPath, JsonConvert.SerializeObject(Notes));
    35. }
    36. }
    37. private void Form1_Load(object sender, EventArgs e)
    38. {
    39. Note.Items.Clear();
    40. Notes.Clear();
    41. try
    42. {
    43. Notes = JsonConvert.DeserializeObjectstring>>(File.ReadAllText(NoteContentPath));
    44. foreach (var item in Notes)
    45. {
    46. Note.Items.Add(item);
    47. }
    48. }
    49. catch (Exception)
    50. {
    51. }
    52. }
    53. }
    54. }
    1. namespace 简易备忘录
    2. {
    3. public partial class Info : Form
    4. {
    5. public Info()
    6. {
    7. InitializeComponent();
    8. }
    9. public bool IsOk = false;
    10. public string MyInfo = "";
    11. private void button1_Click(object sender, EventArgs e)
    12. {
    13. MyInfo = contentTxt.Text.Trim();
    14. if (MyInfo == "")
    15. {
    16. MessageBox.Show("内容不能为空。。。");
    17. return;
    18. }
    19. else
    20. {
    21. IsOk = true;
    22. }
    23. this.Close();
    24. }
    25. private void button2_Click(object sender, EventArgs e)
    26. {
    27. IsOk = false;
    28. this.Close();
    29. }
    30. }
    31. }

    设计器自动生成代码

    1. namespace 简易备忘录
    2. {
    3. partial class Form1
    4. {
    5. ///
    6. /// Required designer variable.
    7. ///
    8. private System.ComponentModel.IContainer components = null;
    9. ///
    10. /// Clean up any resources being used.
    11. ///
    12. /// true if managed resources should be disposed; otherwise, false.
    13. protected override void Dispose(bool disposing)
    14. {
    15. if (disposing && (components != null))
    16. {
    17. components.Dispose();
    18. }
    19. base.Dispose(disposing);
    20. }
    21. #region Windows Form Designer generated code
    22. ///
    23. /// Required method for Designer support - do not modify
    24. /// the contents of this method with the code editor.
    25. ///
    26. private void InitializeComponent()
    27. {
    28. Note = new CheckedListBox();
    29. Add = new Button();
    30. SuspendLayout();
    31. //
    32. // Note
    33. //
    34. Note.BackColor = SystemColors.InactiveCaption;
    35. Note.Font = new Font("Microsoft YaHei UI", 18F, FontStyle.Regular, GraphicsUnit.Point, 134);
    36. Note.FormattingEnabled = true;
    37. Note.Location = new Point(15, 15);
    38. Note.Name = "Note";
    39. Note.Size = new Size(536, 554);
    40. Note.TabIndex = 0;
    41. Note.SelectedIndexChanged += Note_SelectedIndexChanged;
    42. //
    43. // Add
    44. //
    45. Add.BackColor = SystemColors.HotTrack;
    46. Add.Location = new Point(15, 584);
    47. Add.Name = "Add";
    48. Add.Size = new Size(536, 29);
    49. Add.TabIndex = 1;
    50. Add.Text = "添加记事";
    51. Add.UseVisualStyleBackColor = false;
    52. Add.Click += Add_Click;
    53. //
    54. // Form1
    55. //
    56. AutoScaleDimensions = new SizeF(9F, 20F);
    57. AutoScaleMode = AutoScaleMode.Font;
    58. BackColor = SystemColors.ActiveCaption;
    59. ClientSize = new Size(563, 626);
    60. Controls.Add(Add);
    61. Controls.Add(Note);
    62. MaximizeBox = false;
    63. Name = "Form1";
    64. StartPosition = FormStartPosition.CenterScreen;
    65. Text = "备忘录";
    66. Load += Form1_Load;
    67. ResumeLayout(false);
    68. }
    69. #endregion
    70. private CheckedListBox Note;
    71. private Button Add;
    72. }
    73. }
    1. namespace 简易备忘录
    2. {
    3. partial class Info
    4. {
    5. ///
    6. /// Required designer variable.
    7. ///
    8. private System.ComponentModel.IContainer components = null;
    9. ///
    10. /// Clean up any resources being used.
    11. ///
    12. /// true if managed resources should be disposed; otherwise, false.
    13. protected override void Dispose(bool disposing)
    14. {
    15. if (disposing && (components != null))
    16. {
    17. components.Dispose();
    18. }
    19. base.Dispose(disposing);
    20. }
    21. #region Windows Form Designer generated code
    22. ///
    23. /// Required method for Designer support - do not modify
    24. /// the contents of this method with the code editor.
    25. ///
    26. private void InitializeComponent()
    27. {
    28. label1 = new Label();
    29. contentTxt = new RichTextBox();
    30. button1 = new Button();
    31. button2 = new Button();
    32. SuspendLayout();
    33. //
    34. // label1
    35. //
    36. label1.AutoSize = true;
    37. label1.Font = new Font("Microsoft YaHei UI", 18F, FontStyle.Regular, GraphicsUnit.Point, 134);
    38. label1.Location = new Point(-4, 55);
    39. label1.Name = "label1";
    40. label1.Size = new Size(107, 39);
    41. label1.TabIndex = 0;
    42. label1.Text = "内容:";
    43. //
    44. // contentTxt
    45. //
    46. contentTxt.Location = new Point(100, 33);
    47. contentTxt.Name = "contentTxt";
    48. contentTxt.Size = new Size(266, 99);
    49. contentTxt.TabIndex = 1;
    50. contentTxt.Text = "";
    51. //
    52. // button1
    53. //
    54. button1.Location = new Point(100, 159);
    55. button1.Name = "button1";
    56. button1.Size = new Size(94, 29);
    57. button1.TabIndex = 2;
    58. button1.Text = "确定";
    59. button1.UseVisualStyleBackColor = true;
    60. button1.Click += button1_Click;
    61. //
    62. // button2
    63. //
    64. button2.Location = new Point(272, 159);
    65. button2.Name = "button2";
    66. button2.Size = new Size(94, 29);
    67. button2.TabIndex = 3;
    68. button2.Text = "取消";
    69. button2.UseVisualStyleBackColor = true;
    70. button2.Click += button2_Click;
    71. //
    72. // Info
    73. //
    74. AutoScaleDimensions = new SizeF(9F, 20F);
    75. AutoScaleMode = AutoScaleMode.Font;
    76. BackColor = SystemColors.GradientActiveCaption;
    77. ClientSize = new Size(378, 202);
    78. Controls.Add(button2);
    79. Controls.Add(button1);
    80. Controls.Add(contentTxt);
    81. Controls.Add(label1);
    82. MaximizeBox = false;
    83. MinimizeBox = false;
    84. Name = "Info";
    85. StartPosition = FormStartPosition.CenterScreen;
    86. Text = "记事输入窗口";
    87. ResumeLayout(false);
    88. PerformLayout();
    89. }
    90. #endregion
    91. private Label label1;
    92. private RichTextBox contentTxt;
    93. private Button button1;
    94. private Button button2;
    95. }
    96. }

  • 相关阅读:
    题目新颖,内容全面!阿里巴巴又一 Java 面试神册开源!
    Python进价系列 - 16讲 多进程
    浅析-vue.js
    OpenCV-Python快速入门(八):图像金字塔
    关于LWIP的一点记录(二)
    JavaScript入门
    base64编码是啥?
    Symmetric Encoding(Round 946)
    C++算法题 - 矩阵
    ActiveMQ(二)
  • 原文地址:https://blog.csdn.net/XiaoWang_csdn/article/details/139728425