2.4系統主界面
1.效果圖
1.1收銀員
1.2庫管員
2.實現MDI主界面的主要步驟
2.1MDI容器窗體
將窗體的IsMdiContainer屬性設置為True,它就是容器窗體。一種是在窗體的Load()事件中設置,另一種是在屬性中設置
this.IsMdiContainer=True;
注意:容器窗體在顯示后,其客戶區是凹下的,等待子窗體顯示在下凹區。不要在容器窗體的客戶區設計任何控件
2.2MDI子窗體
MDI子窗體就是一般的窗體,其上可以設計任何控件,此前設計過的任何窗體都可以作為MDI子窗體。只要將某個窗體實例的MdiParent屬性設置到一個MDI父窗體,它就是那個父窗體的子窗體,語法為:
窗體實例名.MdiParent=父窗體對象;
例如,下一段代碼編寫在一個MDI父窗體的某個事件處理程序中,創建一個子窗體實例formChild1并將其顯示在MDI父窗體的客戶區中
FormChild formChild1 = new FormChild();
formChild1.MdiParent = this;
formChild1.Show();
3.主要控件
涉及控件:MenuStrip,ToolStrip,StatusStrip,MainForm
MenuStrip:
Name:ms_Admin
ImageScalingSize:20, 20
Location:0, 0
Padding:4, 2, 0, 2
Size:452, 25
TabIndex:0
Text:menuStrip1
ToolStrip:
Name:ts_Admin
ImageScalingSize:20, 20
Location:0, 25
Size:452, 27
TabIndex:1
Text:toolStrip1
StatusStrip:
Name:ss_Admin
ImageScalingSize:20, 20
Location:0, 250
Size:452, 22
TabIndex:2
Text:statusStrip1
MainForm:
Name:MainFormAdmin
AutoScaleMode:Font
ForeColor:ControlText
IsMdiContainer:True
MainMenuStrip:ms_Admin
Size:468, 310
StartPosition:CenterScreen
Text:庫管員主界面/收銀員
WindowState:Maximized
4.主界面的功能與系統結構圖的對應
4.1實際界面主要功能參考
收銀員
庫管員
4.2系統結構圖
5.重要代碼
窗口加載時,顯示當前時間,顯示當前用戶名
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 = UserInfo.userName;
}
每隔一秒鐘更新一下顯示時間
private void timer1_Tick(object sender, EventArgs e)
{
this.tssl_CurrentTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
窗口關閉時,將整個應用程序退出(注意包括登錄窗體)
private void MainFormAdmin_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
修改密碼
private void tsb_Password_Click(object sender, EventArgs e)
{
this.tsmi_Password_Click(sender, e);
}
修改用戶信息
private void tsb_UserInfo_Click(object sender, EventArgs e)
{
this.tsmi_UserInfo_Click(sender, e);
}
錄入商品信息
private void tsb_Record_Click(object sender, EventArgs e)
{
this.tsmi_Record_Click(sender, e);
}
退出系統
private void tsmi_Exit_Click(object sender, EventArgs e)
{
if (MessageBox.Show("確認退出?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
Application.Exit();
}
}