C#完成记事本功能,有用户名、密码输入、登陆、重置、自动换行、保存

都是在一个form中,显示哪个,就把其他的不可见;

namespace book
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (textName.Text == "admin" && textPass.Text == "admin")
            {
                MessageBox.Show("登陆成功,欢迎使用记事本");
                button3.Visible = true;
                button4.Visible = true;
                textBox1.Visible = true;


                textName.Visible = false;
                textPass.Visible = false;
                textBox1.WordWrap = false;


            }
            else {
                MessageBox.Show("登陆失败,请重新输入");
                textPass.Clear();
                textName.Clear();
                textName.Focus();
            }
        }


        private void button2_Click(object sender, EventArgs e)
        {
            textPass.Clear();
            textName.Clear();
            textName.Focus();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            button3.Visible = false;
            button4.Visible = false;
            textBox1.Visible = false;


            textName.Visible = true;
            textPass.Visible = true;
            
        }


        private void button3_Click(object sender, EventArgs e)
        {
            if (button3.Text == "自动换行")
            {
                textBox1.WordWrap = true;
                button3.Text = "取消自动换行";
            }
            else if (button3.Text == "取消自动换行")
            {
                textBox1.WordWrap = false;
                button3.Text = "自动换行";
            }
        }


        private void button4_Click(object sender, EventArgs e)
        {
            FileStream wrifi = new FileStream(@"C:\Users\Administrator\Desktop\a.txt",FileMode.OpenOrCreate ,FileAccess .Write );
            string str = textBox1.Text;
            byte[] nbyte = Encoding.Default.GetBytes(str);
            wrifi.Write(nbyte,0,nbyte.Length );
            MessageBox.Show ("保存成功");
            this.Close();
        }
    }
}



  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一枚努力的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值