2.3系统主界面的制作
2.3.1. GIF效果图



2.3.2. 实现MDI主界面的主要步骤
1.在项目中新建一个父窗体


-
将窗体的IsMdiContainer属性设置为True,使其成为容器窗体。
属性设置
3.为父窗体拉入菜单(Menustrip)工具栏 (toolstrip) 状态栏(statustrip)控件并完成对应功能的编写


4.为父窗体添加子窗体
将某个窗体实例的MdiParent属性设置到一个MDI父窗体,它就是那个父窗体的子窗体,语法为:
窗体实例名.MdiParent=父窗体对象;
例如,下一段代码编写在一个MDI父窗体的某个事件处理程序中,创建一个子窗体实例formChild1并将其显示在MDI父窗体的客户区中:
FormChild formChild1 = new FormChild();
formChild1.MdiParent = this;
formChild1.Show();
2.3.3. 主界面中涉及到的控件以及控件的重要属性、方法

2.3.4.主界面的功能如何与系统结构图对应

2.3.5关键代码及解释
private void bt_Login_Click(object sender, EventArgs e)
{
if (this.cbb_Type.SelectedItem.ToString() == "收银员")
{
if (this.tb_User.Text == "123456" && this.tb_Password.Text == "123456")
{
MessageBox.Show("收银员登录成功");
显示子窗口代码
// 显示收银员主界面
MainFormUser formUser = new MainFormUser();
formUser.userName = this.tb_User.Text.ToString();
formUser.Show();
this.Hide();//隐藏登录界面
}
else
{
MessageBox.Show("用户名或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
保存登录用户名
public string userName;
public MainFormAdmin()
{
InitializeComponent();
}
窗口加载时,显示当前时间,显示当前用户名
private void MainForm_Load(object sender, EventArgs e)
{
this.tssl_CurrentTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
this.tssl_User.Text = this.userName;
}
网友评论