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;
using MyProjectBLL;

namespace MyProject
{
    public partial class FormIndex : Form
    {
        static User user = null;

        public FormIndex()
        {
            InitializeComponent();
        }

        private void FormIndex_Load(object sender, EventArgs e)
        {
            if (user == null)
            {
                user = new User();
            }
            FormLogin formLogin = new FormLogin(user);  //主界面加载前调出登录界面
            formLogin.ShowDialog();
            user = User.QueryByName(user.user_name);  //验证登录用户
            if(user!=null)
                this.txtUsername.Text = user.user_name;
            this.Location = new Point(10, 10);
            this.ShowInTaskbar = true;      //程序是否在系统工具栏显示
            this.WindowState = FormWindowState.Normal;  
            this.IsMdiContainer = true;      //窗体是否是父窗体(窗体容器)
        }

        private void 添加用户ToolStripMenuItem_Click(object sender, EventArgs e)//窗体工具栏上的图标的点击响应方法
        {
            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                this.MdiChildren[i].Close();    //关闭所有子窗体
            }
            this.tstFormIndex.Text = "用户管理--添加用户"; //修改父窗体状态栏
            FormAddUser formAddUser = new FormAddUser(user);//打开想要打开的窗体作为子窗体  
            formAddUser.MdiParent = this;
            formAddUser.Dock = DockStyle.Fill;
            formAddUser.MaximizeBox = true;
            formAddUser.Show();        //显示子窗体 
        }
  private void 查询用户ToolStripMenuItem_Click(object sender, EventArgs e)//窗体工具栏上的图标的点击响应方法
        {
            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                this.MdiChildren[i].Close();    //关闭所有子窗体
            }
            this.tstFormIndex.Text = "用户管理--查询用户"; //修改父窗体状态栏
            FormQueryUser formQueryUser = new FormQueryUser(user);//打开想要打开的窗体作为子窗体  
            formQueryUser.MdiParent = this;
            formQueryUser.Dock = DockStyle.Fill;
            formQueryUser.MaximizeBox = true;
            formQueryUser.Show();       //显示子窗体 
        }
 }
}

你可能感兴趣的:(C#)