c#实现一般程序结构的搭建

      一般中大型程序的画面都是由一个主框架,以及若干业务功能画面组合而成。画面跳转过程中,主框架永远不变,业务功能画面跳转。主框架可以管理业务功能画面,控制其生成,使用,显示,消亡过程。现在给出自写的一个主框架代码。

 

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

namespace CommonComponent
{
    public partial class FormBase : Form
    {
        #region 成员变量声明
  
        private string m_CurrentKey = null;
        #endregion

        #region 构造函数


        public FormBase()
        {
            InitializeComponent();
        }

        #region 方法


         /// <summary>
        /// 根据key值获取相应的画面 ,这个方法由子类执行
        /// </summary>
        /// <param name="panelKey"></param>
        /// <returns></returns>
        protected virtual SubForm GetForm(string panelKey)
        {
            return null;
        }

 

        /// <summary>
        /// 显示出加载的画面

       ///mainPanel是主边框下的一个面板,原理是把业务画面上的控件向这个面板扔
        /// </summary>
        /// <param name="panelKey"></param>
        protected void LoadPanel(string panelKey)
        {


            if (!panelKey.Equals(m_CurrentKey))
            {
              
                    Panel panel = new Panel();
                    SubForm frm = GetForm(panelKey);
                    //设置画面上的按钮是否可用
                    frm.SetBtnEnable();
                    //对画面上其他空间进行预处理
                    frm.PreDealWith();
                    this.MainPanel.Hide();
                    this.MainPanel.Controls.Clear();
                    int count = frm.Controls.Count;
                    for (int i = 0; i < count; i++)
                    {
                        this.MainPanel.Controls.Add(frm.Controls[0]);
                    }
                    this.MainPanel.Show();
                    m_CurrentKey = panelKey;

               
            }
      #endregion
     
        }
    }
}

 

缺点:由于是控件移了过来,窗体本身没有显示,所以与业务窗体有关的方法都不能使用.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值