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
     
        }
    }
}

 

缺點:由於是控件移了過來,窗體本身沒有顯示,所以與業務窗體有關的方法都不能使用.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章