经常会用到类似于下图这样的winform窗体,其中点击各个菜单时于鏊做到内容窗体的切换,今天也记录一直切换的方法
在主窗体放置一个panal,所有的内容窗体均在改panal上呈现,实现以下方法
///实例化主窗体
private void FrmSetup_Load(object sender, EventArgs e)
{
this.btnSystem_Click(null, null);
}
///初始化内容窗体
public FrmSetup(uint uiDeviceSN)
: this()
{
m_uiDeviceSN = uiDeviceSN;
m_devSetupRefObj = new DevSetupRefObj(m_uiDeviceSN);
string sIniPath = this.m_uiDeviceSN.ToString("D08") + "\\Setup\\Setup.ini";
if (File.Exists(sIniPath))
{
m_devSetupRefObj.LoadLocalSetup(sIniPath);
}
else
{
m_devSetupRefObj.LoadDeviceSetup();
}
m_frmBaseSysSetup = new FrmBaseSystemSetup(m_uiDeviceSN, m_devSetupRefObj);
m_frmEditSetup = new FrmEditSetup(m_uiDeviceSN, m_devSetupRefObj);
m_frmPrintSetup = new FrmPrintSetup(m_uiDeviceSN, m_devSetupRefObj);
m_frmUserSetup = new FrmUserSetup(m_uiDeviceSN, m_devSetupRefObj);
m_frmMoreSetup = new FrmMoreSetup(m_uiDeviceSN, m_devSetupRefObj);
m_frmRegister = new FrmRegister(m_uiDeviceSN, m_devSetupRefObj);
}
///实例化内容窗体
FrmBaseSystemSetup m_frmBaseSysSetup;
FrmEditSetup m_frmEditSetup;
FrmPrintSetup m_frmPrintSetup;
FrmUserSetup m_frmUserSetup;
FrmMoreSetup m_frmMoreSetup;
FrmRegister m_frmRegister;
private void btnSystem_Click(object sender, EventArgs e)
{
this.ShowSystem();
this.HideEdit();
this.HidePrint();
this.HideUser();
this.HideMore();
this.HideRegister();
}
///窗体切换
private void ShowUser()
{
pnlShow.Controls.Clear();
m_frmUserSetup.TopLevel = false;
m_frmUserSetup.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
pnlShow.Controls.Add(m_frmUserSetup);
this.m_frmUserSetup.ShowForm();
}
以上就是大致思路。