c# winform 单窗口隐藏控件,登陆演示

 

 

 登陆成功后自动隐藏 用户名和文本框等控件,自动换行功能

 

namespace WindowsFormsApp1
{
    public partial class Form : System.Windows.Forms.Form
    {
        public Form()
        {
            InitializeComponent();
        }

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

        }

        private void Button1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void button2_MouseEnter(object sender, EventArgs e)
        {

        }


        private void timer1_Tick(object sender, EventArgs e)
        {
          

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (textBox1.Text == "yaoyue" && textBox2.Text == "123456") //用户名 密码验证
            {
                button3.Visible = true;
                button4.Visible = true;
                textBox3.Visible = true;
                label1.Visible = false;   //先登陆时隐藏 控件
                label2.Visible = false;
                textBox1.Visible = false;
                textBox2.Visible = false;
                button1.Visible = false;
                button2.Visible = false;
            }
            else
            {

                MessageBox.Show("用户名或密码错误!");

            }
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            textBox2.Clear();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (button3.Text == "自动换行")          //按钮和功能切换
            {
                textBox3.WordWrap = true;
                button3.Text = "取消换行";
            }
            else
            {
                textBox3.WordWrap = false;
                button3.Text = "自动换行";

            }

        }

        private void button4_Click(object sender, EventArgs e)       //用filestream演示
        {
            string path = @"d:\1.txt";
            using (FileStream fs=new FileStream(path,FileMode.OpenOrCreate,FileAccess.Write))
            {     
                byte[] conb = System.Text.Encoding.Default.GetBytes(textBox3.Text);  //注意写法, system.text.encording 下
                fs.Write(conb,0,conb.Length);

                MessageBox.Show("写入成功!");
            }
           
        }
    }
}

  

posted @ 2021-04-10 13:27  遥月  阅读(1273)  评论(0)    收藏  举报