日期:2014-05-17  浏览次数:20685 次

C#--第十一周任务一登录窗体与主窗体

首先是登陆窗体:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {

        }
        Form frmMain;
        private void button1_Click(object sender, EventArgs e)
        {//要求:在登录窗体中,假设当用户输入账号为“zhangsan”,且密码为“123”(密码显示为*)
            //,则通过登录,销毁登录窗体,同时打开主窗体。否则,给出错误提示,如“账号或密码错误”
            if(textBox1.Text.Equals("zhangsan")&&textBox2.Text.Equals("123"))
            {
                frmMain = new frmMain();

                frmMain.Show();

               

            }

            else 
            {
                MessageBox.Show("您的账号或密码错误");
            }

            

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}


接着是主窗体:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {

        }

        private void 文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 打开主窗体1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frm子窗体1 f = new frm子窗体1();
            f.Show();
            f.MdiParent = this;



        }

        private void 打开主窗体2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (var item in this.MdiChildren)
            {
                item.Dispose();
            }

            frm子窗体2 f1 = new frm子窗体2();
            f1.Show();
            f1.MdiParent = this;

        }

        private void frmMain_Load_1(object sender, EventArgs e)
        {

        }
    }
}


最后是两个子窗体

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class frm子窗体1 : Form
    {
        public frm子窗体1()
        {
            InitializeComponent();
        }

        private void frm子窗体1_Load(object sender, EventArgs e)
        {

        }
    }
}


 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class frm子窗体2 : Form
    {
        public frm子窗体2()
        {
            InitializeComponent();
        }

        private void frm子窗体2_Load(object sender, EventArgs e)
        {

        }
    }
}