成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

詳解Winform假框架的設計應用

開發 后端
在這里我們將介紹Winform假框架的設計應用,希望本文能對大家了解SCSF有所幫助。

對于Winform假框架的設計很多人不太理解,但是對于SCSF(Smart Client Software Factory)相信大家不太陌生,本文將從Winform假框架的設計應用開始談起。

學習SCSF 有寫日子了,對該框架有一些了解,于是自己腦子發熱寫了個假SCSF雖然不成熟,但是是對自己學習的一個總結。

主要框架示意圖(解決方案):

主要框架示意圖

Winform假框架概念:

1.整個系統共用一個WorkItem(工作單元).

2.WorkItem中有 Service集合.

3.初始默認使用ShellForm.

WorkItem:

WorkItem 是自定義的靜態類,在程序啟動時加載默認設置,當前是代碼以后會使用XML配置。

WorkItem代碼:

  1. WorkItem  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.Text;  
  5. using System.Windows.Forms;  
  6. using Bob.Library.UI;  
  7. using Bob.Library.Services;  
  8.  
  9. namespace Bob.Library.WorkItems  
  10. {  
  11.     public static class WorkItem  
  12.     {  
  13.         private static Shell _ShellForm;  
  14.         private static IServices _Services;  
  15.  
  16.         public static void InitWorkItem()  
  17.         {  
  18.             InitServices();  
  19.             InitShellForm();  
  20.         }  
  21.  
  22.  
  23.         public static Shell ShellForm  
  24.         {  
  25.             get 
  26.             {  
  27.                 if (_ShellForm == null)  
  28.                 {  
  29.                     InitShellForm();  
  30.                 }  
  31.                 return _ShellForm;  
  32.             }  
  33.         }  
  34.  
  35.         private static void InitShellForm()  
  36.         {  
  37.             _ShellForm = new Shell();  
  38.         }  
  39.  
  40.  
  41.         public static Bob.Library.Services.IServices Services  
  42.         {  
  43.             get 
  44.             {  
  45.                 if (_Services == null)  
  46.                 {  
  47.                     InitServices();  
  48.                 }  
  49.                 return _Services;  
  50.             }  
  51.         }  
  52.  
  53.         private static void InitServices()  
  54.         {  
  55.             _Services = new Services.Services();  
  56.         }  
  57.  
  58.     }  

WorkItem 中有一個 IServices 類型的屬性 Services,該屬性用于保存全局的Service,IService 有 AddService、GetServiceByKey、Clear 三個方法:實現 添加、獲取、清空Service操作。

代碼:

  1. IServices Services  
  2. //接口  
  3. using System;  
  4. using System.Collections.Generic;  
  5. using System.Text;  
  6.  
  7. namespace Bob.Library.Services  
  8. {  
  9.     public interface IServices  
  10.     {  
  11.         TService AddService(string key,TService service) where TService : class;  
  12.  
  13.         TService GetServiceByKey(string key) where TService : class;  
  14.  
  15.         void Clear();  
  16.     }  
  17. }  
  18.  
  19.  
  20.  
  21. //實現  
  22. using System;  
  23. using System.Collections.Generic;  
  24. using System.Text;  
  25.  
  26. namespace Bob.Library.Services  
  27. {  
  28.     public class Services :IServices  
  29.     {  
  30.         IDictionary _Services;  
  31.  
  32.         public Services()  
  33.         {  
  34.             InitServices();  
  35.         }  
  36.  
  37.         private void InitServices()  
  38.         {  
  39.             _Services = new Dictionary();  
  40.         }  
  41.       
  42.         IServices#region IServices   
  43.  
  44.         public TService  AddService(string key, TService service) where TService : class 
  45.         {  
  46.             _Services[key] = service;  
  47.             return _Services[key] as TService;  
  48.         }  
  49.  
  50.         public TService  GetServiceByKey(string key) where TService : class 
  51.         {  
  52.             object service = _Services[key];  
  53.             return service is TService ? service as TService : null;  
  54.         }  
  55.  
  56.         public void  Clear()  
  57.         {  
  58.             InitServices();  
  59.         }  
  60.  
  61.         #endregion  
  62.     }  

WorkItem 中還有一個 Shell 類型的ShellForm 屬性:該屬性是一個MDI窗口的實例,作為系統的父容器。

設計圖:

[[6263]]

代碼:

  1. Shell  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.ComponentModel;  
  5. using System.Data;  
  6. using System.Drawing;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9.  
  10. namespace Bob.Library.UI  
  11. {  
  12.     public partial class Shell : Form  
  13.     {  
  14.         public Shell()  
  15.         {  
  16.             InitializeComponent();  
  17.             _AppMenu.Text = AppMenuName;  
  18.             _ExitMenu.Text = ExitString;  
  19.         }  
  20.  
  21.         public string FormName  
  22.         {  
  23.             get 
  24.             {  
  25.                 return this.ParentForm.Text;  
  26.             }  
  27.             set 
  28.             {  
  29.                 this.ParentForm.Text = value;  
  30.             }  
  31.         }  
  32.  
  33.           
  34.         public void StatusUpdate(string message)  
  35.         {  
  36.             _ShellStatus.Text = message;  
  37.         }  
  38.  
  39.         private void _ExitAppMenu_Click(object sender, EventArgs e)  
  40.         {  
  41.             if (MessageBox.Show("Exit ?""Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)  
  42.             {  
  43.                 Environment.Exit(0);  
  44.             }  
  45.         }  
  46.  
  47.  
  48.         MenuItemString#region MenuItemString  
  49.         private string _AppName = "Application";  
  50.         private string _ExitName = "Exit";  
  51.         public string AppMenuName  
  52.         {  
  53.             get { return _AppName; }  
  54.             set   
  55.             {   
  56.                 _AppName = value;  
  57.                 _AppMenu.Text = _AppName;  
  58.             }  
  59.         }  
  60.  
  61.         public string ExitString  
  62.         {  
  63.             get { return _ExitName; }  
  64.             set 
  65.             {  
  66.                 _ExitName = value;  
  67.                 _ExitMenu.Text = _ExitName;  
  68.             }  
  69.         }  
  70.  
  71.         #endregion  
  72.  
  73.         public MenuStrip ShellMenu  
  74.         {  
  75.             get 
  76.             {  
  77.                 return _ShellMenu;  
  78.             }  
  79.         }  
  80.  
  81.     }  

Shell 中有一個菜單控件,一個狀態欄控件,將兩個控件作為屬性發布。初始加載了一個菜單項 _AppMenu ,將菜單項的Text屬性布.然后為_AppMenu 添加一個子菜單項ExitMenu 同時將他的Text屬性發布。為_ExitMenu 添加事件 _ExitAppMenu_Click;然后發布一個方法 StatusUpdate(string message) 在狀態欄顯示提示消息。

準備工作完成,開始項目開發:首先創建一個普通的Winform項目,將 Bob.Library 應用進來,在系統開始類Program.cs 中添加 WorkItem的加載 代碼如下:

  1. Program  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.Linq;  
  5. using System.Windows.Forms;  
  6. using Bob.Library.WorkItems;  
  7. using ArchitectureDemo.Services;  
  8.  
  9. namespace ArchitectureDemo  
  10. {  
  11.     static class Program  
  12.     {  
  13.         [STAThread]  
  14.         static void Main()  
  15.         {  
  16.             Application.EnableVisualStyles();  
  17.  
  18.             Application.SetCompatibleTextRenderingDefault(false);  
  19.  
  20.             InitWorkItem();  
  21.  
  22.             Application.Run(WorkItem.ShellForm);  
  23.         }  
  24.  
  25.         private static void InitWorkItem()  
  26.         {  
  27.             WorkItem.InitWorkItem();  
  28.  
  29.             AddServices();  
  30.  
  31.             AddModules();  
  32.         }  
  33.  
  34.  
  35.  
  36.         private static void AddModules()  
  37.         {  
  38.             WorkItem.ShellForm.AppMenuName = "程序";  
  39.  
  40.             WorkItem.ShellForm.ExitString = "退出";  
  41.  
  42.             AddCustomModule();  
  43.         }  
  44.  
  45.         private static void AddCustomModule()  
  46.         {  
  47.             ToolStripMenuItem _btnCutomMenuItem = new ToolStripMenuItem("自定義模塊");  
  48.  
  49.             ToolStripItem _btnShowMyForm = new ToolStripButton("彈出");  
  50.  
  51.             _btnShowMyForm.Click += new EventHandler(ShowMyForm_Click);  
  52.  
  53.             _btnCutomMenuItem.DropDownItems.Add(_btnShowMyForm);  
  54.  
  55.             WorkItem.ShellForm.ShellMenu.Items.Add(_btnCutomMenuItem);  
  56.         }  
  57.  
  58.         private static void ShowMyForm_Click(object sender, EventArgs e)  
  59.         {  
  60.             MyForm mForm = new MyForm();  
  61.  
  62.             mForm.MdiParent = WorkItem.ShellForm;  
  63.  
  64.             mForm.Show();  
  65.         }  
  66.  
  67.         private static void AddServices()  
  68.         {  
  69.             IFormService service = WorkItem.Services.AddService("FormService"new FormService());  
  70.         }  
  71.     }  

首先:加載WorkItem添加InitWorkItem() 方法,將Bob.Library中的ShellForm 實例化。然后加載Service 和模塊 AddServices() 添加一個Key為FormService的IFormService 實例,該實例在MyForm中有用到。

  1. GetService  
  2.         private void btnGetGUID_Click(object sender, EventArgs e)  
  3.         {  
  4.             IFormService service = WorkItem.Services.GetServiceByKey("FormService");  
  5.             txtGUID.Text = service.GetGuidString();  
  6.         } 

AddModules() ,模擬的添加一個自定義模塊,AddCustomModule(),為該模塊添加獨享的菜單,為該模塊添加子菜單,
為子菜單綁定事件.

然后我們讓程序開始Run 我們的 Shell   Application.Run(WorkItem.ShellForm);

原文標題:Winform 應用 【假框架】

鏈接:http://www.cnblogs.com/duoluodaizi/archive/2009/10/12/1582000.html

【編輯推薦】

  1. 詳解TripleDES實現C# 加密操作
  2. 淺析C# WinForm控件開發前期準備
  3. 詳解C# WinForm自定義控件的使用和調試
  4. C# Attribute的概念與使用淺析
  5. C# AttributeUsage的使用淺析
責任編輯:彭凡 來源: 博客園
相關推薦

2023-07-03 07:39:43

Spring框架設計模式

2010-06-11 14:55:20

2012-11-20 10:04:46

Winform開發

2010-06-13 09:15:16

WinForm窗體

2013-04-23 09:31:12

Winform開發框架

2010-08-27 09:11:27

Python單元測試

2010-08-11 10:24:46

Flex開發

2011-05-03 09:45:25

噴墨打印機假故障

2009-11-30 08:38:35

WinForm

2010-08-10 17:13:58

Flex技術

2017-02-27 09:36:01

AndroidMVVM架構

2023-02-07 07:43:27

微服務應用框架

2023-01-12 08:00:00

SpringClou微服務框架

2012-08-21 11:26:17

Winform

2010-03-16 14:50:49

Python web框

2011-11-14 10:41:15

Winform數據管理模塊Items

2024-10-24 17:13:55

WinformUI多線程

2009-04-13 09:23:41

.NET 2.0Winform經驗

2015-06-24 09:25:51

應用框架

2012-12-11 10:15:02

Winform開發框架
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产日韩精品视频 | 欧美中文字幕一区二区三区亚洲 | 黄色一级毛片免费看 | 国产精品福利网站 | 精品一区二区在线观看 | 久久久久久久久国产成人免费 | 国产精品视频导航 | 中文字幕在线精品 | 久久在看| 天天曰夜夜操 | 第一区在线观看免费国语入口 | 免费午夜电影 | 亚洲一二三区在线观看 | 亚洲午夜精品久久久久久app | 亚洲精品一区二区三区在线 | 中文字幕亚洲欧美日韩在线不卡 | 久久伊人免费视频 | 久久久成人精品 | 欧美日韩理论 | 天天看片天天干 | 激情婷婷 | 亚洲精品不卡 | 9999久久 | 国产日韩欧美 | 韩日av在线 | 日韩欧美理论片 | 91综合网| 日韩欧美一区二区三区免费观看 | 国产一区二区三区久久久久久久久 | 久久精品亚洲成在人线av网址 | 精品国产乱码久久久久久蜜柚 | 亚洲色在线视频 | 国产欧美一区二区久久性色99 | 欧美a在线 | 天天操操操操操 | 91大神在线资源观看无广告 | 天堂一区 | 在线免费视频一区 | 久久免费精品 | 91久久爽久久爽爽久久片 | 国产特黄一级 |