c#实现一般程序结构的搭建
2009-07-30 14:30
260 查看
一般中大型程序的画面都是由一个主框架,以及若干业务功能画面组合而成。画面跳转过程中,主框架永远不变,业务功能画面跳转。主框架可以管理业务功能画面,控制其生成,使用,显示,消亡过程。现在给出自写的一个主框架代码。
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
}
}
}
缺点:由于是控件移了过来,窗体本身没有显示,所以与业务窗体有关的方法都不能使用.
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
}
}
}
缺点:由于是控件移了过来,窗体本身没有显示,所以与业务窗体有关的方法都不能使用.
相关文章推荐
- C#一般处理程序+html实现短信发送
- C# 实现 HTML+一般处理程序图片上传功能如图!
- C#使用EPPlus.dll动态库在一般处理程序中实现将datatable导出到excel
- 在C#程序中实现插件架构
- C#实现的中国象棋程序开发笔记——遇到困难,请大家帮忙!!
- c# Winform 程序自动更新实现方法
- c# 一般处理程序(Jquery ajax调用)
- C language 使用if…else if…else语句实现多分支选择结构*(语法结构同C#)
- asp.net c# 在一般处理程序中不能获取Session值
- C#实现木马程序
- 用单链表结构实现算法2.2的程序
- C#程序实现动态调用非托管的DLL文件
- (转载) 在C#程序中实现热键
- C#实现_______个人记账程序__修改
- C#实现从dll程序集中动态加载窗体
- 不破坏HTML结构的情况下等长截取字符串(C#正则表达式实现)
- C#程序实现动态调用DLL的研究(转载)
- C#实现联通短信Sgip协议程序源码
- C#语言实现网站爬虫蜘蛛程序