1、在程序加载的时候,取消文本框的自动换行,以及让两个按钮和文本框隐藏。
    2、点击登陆,判断是否登陆成功。
    3、自动换行功能。
    4、保存文本到一个指定目录下。

    image.png

    1. public partial class Form1 : Form
    2. {
    3. public Form1()
    4. {
    5. InitializeComponent();
    6. }
    7. private void textBox1_TextChanged(object sender, EventArgs e)
    8. {
    9. }
    10. private void Form1_Load(object sender, EventArgs e)
    11. {
    12. txtWords.WordWrap = false;
    13. btnWordWarp.Visible = false;
    14. btnSave.Visible = false;
    15. txtWords.Visible = false;
    16. btnClose.Visible = false;
    17. }
    18. /// <summary>
    19. /// ,用户点击登陆,判断是否登陆成功
    20. /// </summary>
    21. /// <param name="sender"></param>
    22. /// <param name="e"></param>
    23. private void btnLogin_Click(object sender, EventArgs e)
    24. {
    25. string name = txtName.Text.Trim();
    26. string pwd = txtPwd.Text;
    27. if (name == "admin" && pwd == "888888")
    28. {
    29. MessageBox.Show("欢迎使用 <微咲> 简单记事本!");
    30. btnWordWarp.Visible = true;
    31. btnSave.Visible = true;
    32. txtWords.Visible = true;
    33. btnClose.Visible = true;
    34. lblName.Visible = false;
    35. lblPwd.Visible = false;
    36. txtName.Visible = false;
    37. txtPwd.Visible = false;
    38. btnLogin.Visible = false;
    39. btnReset.Visible = false;
    40. btnClose1.Visible = false;
    41. }
    42. else //登陆失败
    43. {
    44. MessageBox.Show("用户名或密码错误,请重新登陆!");
    45. //用户输入失败后,清空两个文本框
    46. txtName.Clear();
    47. txtPwd.Clear();
    48. //让焦点到TxtName中
    49. txtName.Focus();
    50. }
    51. }
    52. /// <summary>
    53. /// 用户点击重置
    54. /// </summary>
    55. /// <param name="sender"></param>
    56. /// <param name="e"></param>
    57. private void btnReset_Click(object sender, EventArgs e)
    58. {
    59. //用户点击重置后,清空两个文本框
    60. txtName.Clear();
    61. txtPwd.Clear();
    62. //让焦点到TxtName中
    63. txtName.Focus();
    64. }
    65. /// <summary>
    66. /// 自动换行
    67. /// </summary>
    68. /// <param name="sender"></param>
    69. /// <param name="e"></param>
    70. private void btnWordWarp_Click(object sender, EventArgs e)
    71. {
    72. //当前是否自动换行
    73. if (btnWordWarp.Text=="自动换行")
    74. {
    75. //取消自动换行
    76. txtWords.WordWrap = true;
    77. btnWordWarp.Text = "取消自动换行";
    78. }
    79. else if(btnWordWarp.Text == "取消自动换行")
    80. {
    81. txtWords.WordWrap = false;
    82. btnWordWarp.Text = "自动换行";
    83. }
    84. }
    85. /// <summary>
    86. /// 保存文本
    87. /// </summary>
    88. /// <param name="sender"></param>
    89. /// <param name="e"></param>
    90. private void btnSave_Click(object sender, EventArgs e)
    91. {
    92. using (FileStream fsWrite = new FileStream(@"C:\Users\46124\Desktop\记事本.txt", FileMode.Append, FileAccess.Write))
    93. {
    94. string userInput = txtWords.Text.Trim()+"\n";
    95. byte[] buffer = System.Text.Encoding.Default.GetBytes(userInput);
    96. fsWrite.Write(buffer, 0, buffer.Length);
    97. }
    98. MessageBox.Show("保存成功");
    99. }
    100. private void btnClose_Click(object sender, EventArgs e)
    101. {
    102. this.Close();
    103. }
    104. private void btnClose1_Click(object sender, EventArgs e)
    105. {
    106. this.Close();
    107. }
    108. }