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

ASP.NET控件設計時操作列表與模板編輯淺析

開發 后端
ASP.NET控件設計時操作列表與模板編輯向你介紹了ASP.NET控件設計時操作列表與模板編輯的相關內容,希望本文對你有所幫助。

ASP.NET控件設計時操作列表與模板編輯的基本內容:

 

ASP.NET控件設計時操作列表與模板編輯一.智能標記

先看一張圖.

智能標記 

GridView右側的小三角可以很輕松的幫助我們設置常用的屬性,如下面的啟動分頁,啟用排序等,通過這樣的方式我們可以很快的完成工作。我們稱這樣的任務菜單為智能標記.

下面來看看ASP.NET控件設計時操作列表與模板編輯如何實現

1.重寫ControlDesigner的ActionLists屬性

你必須重寫這個屬性,返回你自定義的智能標記集合(即DesignerActionListCollection),這里假設CustomControlActionList為自定義的智能

  1. public class SampleControlDesigner : ControlDesigner  
  2. {  
  3.     public SampleControlDesigner()  
  4.         : base()  
  5.     {  
  6.     }  
  7.  
  8.     //創建一個自定義操作列表集合  
  9.     public override DesignerActionListCollection ActionLists  
  10.     {  
  11.         get 
  12.         {  
  13.             DesignerActionListCollection actionLists = new DesignerActionListCollection();  
  14.             actionLists.Add(new CustomControlActionList(this));  
  15.  
  16.             return actionLists;  
  17.         }  
  18.     }    

2.CustomControlActionList 自定義項列表

2.1項列表分類

(1)標題面板

(2)屬性面板

(3)方法面板

類圖如下

類圖 

看個效果圖,你就明白怎么回事了

效果圖 

2.2實現

(1)繼承DesignerActionList類,重寫GetSortedActionItems方法添加自定義項面板集合,即2.1的三種項面板

  1. public override DesignerActionItemCollection GetSortedActionItems()  
  2. {  
  3.     if (items == null)  
  4.     {  
  5.         items = new DesignerActionItemCollection();  
  6.         // 添加標題面板  
  7.         items.Add(new DesignerActionHeaderItem("快速設置面板測試:"));  
  8.         //添加屬性相關面板  
  9.         items.Add(new DesignerActionPropertyItem("Visible",  
  10.                  "是否顯示"));  
  11.         items.Add(new DesignerActionPropertyItem("Width",  
  12.                 "設置寬度"));  
  13.         items.Add(new DesignerActionPropertyItem("Height",  
  14.                "設置高度"));  
  15.         // 添加方法相關面板  
  16.  
  17.         items.Add(new DesignerActionMethodItem(this"FormatBlue""定義背景為藍色"true));  
  18.         items.Add(new DesignerActionMethodItem(this"FormatRed""定義背景為紅色"true));  
  19.         items.Add(new DesignerActionMethodItem(this"FormatWhite""定義背景為白色"true));  
  20.           
  21.     }  
  22.     return items;  

(2)屬性,方法項面板的實現

如果你設置屬性的話,則必須在CustomControlActionList定義屬性,方法也相同,代碼如下

  1. #region 自定義方法  
  2.  
  3.         public void FormatBlue()  
  4.         {  
  5.             SampleControl ctrl = (SampleControl)_parent.Component;  
  6.             TransactedChangeCallback toCall = new TransactedChangeCallback(DoFormat);  
  7.             ControlDesigner.InvokeTransactedChange(ctrl, toCall, "FormatBlue""FormatBlue");  
  8.         }  
  9.  
  10.         public void FormatRed()  
  11.         {  
  12.             SampleControl ctrl = (SampleControl)_parent.Component;  
  13.             TransactedChangeCallback toCall = new TransactedChangeCallback(DoFormat);  
  14.             ControlDesigner.InvokeTransactedChange(ctrl, toCall, "FormatRed""FormatRed");  
  15.         }  
  16.  
  17.         public void FormatWhite()  
  18.         {  
  19.             SampleControl ctrl = (SampleControl)_parent.Component;  
  20.             //定義委托  
  21.             TransactedChangeCallback toCall = new TransactedChangeCallback(DoFormat);  
  22.             ControlDesigner.InvokeTransactedChange(ctrl, toCall, "FormatWhite""FormatWhite");  
  23.         }  
  24.  
  25.         #endregion 
  1. #region 自定義屬性  
  2.  
  3.         public bool Visible  
  4.         {  
  5.             get 
  6.             {  
  7.                 SampleControl ctrl = (SampleControl)_parent.Component;  
  8.                 return ctrl.Visible;  
  9.             }  
  10.             set 
  11.             {  
  12.                     PropertyDescriptor propDesc = TypeDescriptor.GetProperties(_parent.Component)["Visible"];  
  13.                     propDesc.SetValue(_parent.Component, value);  
  14.  
  15.             }  
  16.         }  
  17.  
  18.         public Unit Width  
  19.         {  
  20.             get 
  21.             {  
  22.                 SampleControl ctrl = (SampleControl)_parent.Component;  
  23.                 return ctrl.Width;  
  24.             }  
  25.             set 
  26.             {  
  27.                 PropertyDescriptor propDesc = TypeDescriptor.GetProperties(_parent.Component)["Width"];  
  28.                 propDesc.SetValue(_parent.Component, value);  
  29.             }  
  30.         }  
  31.  
  32.         public Unit Height  
  33.         {  
  34.             get 
  35.             {  
  36.                 SampleControl ctrl = (SampleControl)_parent.Component;  
  37.                 return ctrl.Height;  
  38.             }  
  39.             set 
  40.             {  
  41.                 PropertyDescriptor propDesc = TypeDescriptor.GetProperties(_parent.Component)["Height"];  
  42.                 propDesc.SetValue(_parent.Component, value);  
  43.             }  
  44.         }  
  45.  
  46.         #endregion  
  47.  
  48.         public bool DoFormat(object arg)  
  49.         {  
  50.             SampleControl ctl = (SampleControl)_parent.Component;  
  51.             string fmt = (string)arg;  
  52.  
  53.             PropertyDescriptor backColorProp = TypeDescriptor.GetProperties(ctl)["BackColor"];  
  54.  
  55.             switch (fmt)  
  56.             {  
  57.                 case "FormatBlue":  
  58.                     backColorProp.SetValue(ctl, Color.Blue);  
  59.                     break;  
  60.                 case "FormatRed":  
  61.  
  62.                     backColorProp.SetValue(ctl, Color.Red);  
  63.                     break;  
  64.                 case "FormatWhite":  
  65.                     backColorProp.SetValue(ctl, Color.White);  
  66.                     break;  
  67.             }  
  68.  
  69.             //刷新設計時html標記  
  70.             _parent.UpdateDesignTimeHtml();  
  71.  
  72.             return true;  
  73.         } 

以上步驟完成以后就大功告成了,接著則與相關控件關聯起來就可以了,效果圖在上面已經看過了.

[DesignerAttribute(typeof(SampleControlDesigner))]

ASP.NET控件設計時操作列表與模板編輯二.模板編輯器

模板編輯器 

上面的模板編輯界面相信大家都很熟悉吧.設置支持怎么少的了模板呢.設置時模板編輯實現比較簡單,下面來看下如何實現

這里自定義的模板控件不再列出

1.重寫ControlDesigner類的TemplateGroups返回自定義模板組集合即(TemplateGroupCollection)

添加步驟跟表格的添加類似,td add tr然后table add td

模板則是TemplateGroup add TemplateDefinition 然后TemplateGroupCollection add TemplateGroup

代碼如下

  1. public override TemplateGroupCollection TemplateGroups  
  2.         {  
  3.             get 
  4.             {  
  5.  
  6.                 if (col == null)  
  7.                 {  
  8.                     col = base.TemplateGroups;  
  9.  
  10.                     TemplateGroup tempGroup;  
  11.                     TemplateDefinition tempDef;  
  12.                     TemplateGroupsSample ctl;  
  13.  
  14.                     ctl = (TemplateGroupsSample)Component;  
  15.  
  16.                     // 創建模板分組一  
  17.                     tempGroup = new TemplateGroup("模板A組");  
  18.  
  19.                     //提供在設置時編輯模板  
  20.                     tempDef = new TemplateDefinition(this"Template A1",  
  21.                         ctl, "Template1"false);  
  22.  
  23.                     tempGroup.AddTemplateDefinition(tempDef);  
  24.  
  25.                    
  26.                     tempDef = new TemplateDefinition(this"Template A2",  
  27.                         ctl, "Template2"false);  
  28.  
  29.                     tempGroup.AddTemplateDefinition(tempDef);  
  30.  
  31.            
  32.                     col.Add(tempGroup);  
  33.  
  34.                     // 創建模板分組二  
  35.                     tempGroup = new TemplateGroup("模板B組");  
  36.                     tempDef = new TemplateDefinition(this"Template B1",  
  37.                         ctl, "Template3"true);  
  38.                     tempGroup.AddTemplateDefinition(tempDef);  
  39.                     tempDef = new TemplateDefinition(this"Template B2",  
  40.                         ctl, "Template4"true);  
  41.                     tempGroup.AddTemplateDefinition(tempDef);  
  42.                     col.Add(tempGroup);  
  43.                 }  
  44.  
  45.                 return col;  
  46.             }  
  47.         } 

這里注意TemplateDefinition構造函數的***一個屬性,true則在設計時編輯只能添加服務器控件

2.初始化啟用設計時模板編輯

我們還需要在Initialize方法中調用SetViewFlags方法啟用設計時模板編輯

  1. public override void Initialize(IComponent component)  
  2. {  
  3.    
  4.     base.Initialize(component);  
  5.    
  6.     SetViewFlags(ViewFlags.TemplateEditing, true);  

3.提供默認矩形標識符,為控件提供說明

如下圖,DataList默認情況下給予如下提示

DataList默認情況 

我們可以通過重寫GetDesignTimeHtml方法調用CreatePlaceHolderDesignTimeHtml方法創建一個矩形標識符來實現

  1. public override string GetDesignTimeHtml()  
  2. {  
  3.     return CreatePlaceHolderDesignTimeHtml("右擊或選擇編輯模板面板來編輯模板內容");  

好了,完成了,接著要做的就是與相關模板控件關聯起來了

平時大家都太忙了,上面功能有跟沒有沒多大關系,不過常用控件屬性和功能,有設計時支持一定會讓使用的更加有效.

ASP.NET控件設計時操作列表與模板編輯的相關內容就向你介紹到這里,希望對你了解ASP.NET控件設計時操作列表與模板編輯有所幫助。

【編輯推薦】

  1. ASP.NET模板控件開發淺析
  2. ASP.NET數據綁定控件開發淺析
  3. ASP.NET控件設計時支持淺析
  4. ASP.NET2.0數據源控件的用法淺析
  5. ASP.NET控件設計時支持之自動格式設置淺析
責任編輯:仲衡 來源: 博客園
相關推薦

2009-08-07 16:32:52

ASP.NET控件設計時支

2009-08-07 15:24:16

ASP.NET模板控件

2009-08-07 17:49:44

控件設計器

2009-08-07 17:09:24

ASP.NET控件設計時支持

2009-08-07 17:59:35

控件設計器

2009-07-27 17:25:53

ASP.NET驗證控件

2009-08-04 14:18:49

ASP.NET郵件列表

2009-08-05 16:53:14

ASP.NET組件設計

2009-08-10 13:32:15

ASP.NET TimASP.NET組件設計

2009-07-24 09:57:25

ASP.NET HTM

2009-08-07 15:34:15

ASP.NET數據綁定

2009-08-04 15:20:59

ASP.NET數據驗證數據驗證控件

2009-08-03 18:29:31

GridView與Da

2009-07-28 16:21:03

Asp.net AjaAutoComplet

2009-08-06 18:18:27

ASP.NET控件開發ASP.NET復合控件

2009-08-06 17:13:56

ASP.NET自定義控

2009-08-06 15:21:45

ASP.NET控件開發RenderConte

2009-08-03 18:00:00

ASP.NET服務器控

2009-12-02 09:07:45

ASP.NET 4.0

2009-07-24 15:47:35

ASP.NET與ASP
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 99re国产| 成人激情视频免费在线观看 | 一级a性色生活片久久毛片 午夜精品在线观看 | 午夜视频一区二区 | 日韩欧美中文 | av大片在线观看 | 日韩精品一区二区三区免费视频 | 国产一区不卡 | 精品亚洲一区二区 | 麻豆av网| 91在线精品视频 | 精品一区二区三区免费毛片 | 日韩视频一区二区在线 | 亚洲一区在线免费观看 | 亚洲精品成人av久久 | 免费观看成人鲁鲁鲁鲁鲁视频 | 亚洲天堂av一区 | 色婷婷综合久久久久中文一区二区 | 91精品国产乱码久久久久久久久 | 欧美日韩在线一区 | 丁香久久| 秋霞a级毛片在线看 | 羞羞的视频网站 | 二区欧美| 久久久久亚洲国产| 一区二区视频在线观看 | 欧美一区二区三区四区在线 | 一区欧美| 亚洲激情一级片 | 国产精品久久久久久久久图文区 | 美国一级黄色片 | 欧美日韩精品免费 | 欧美一级做性受免费大片免费 | 国产视频精品在线观看 | 亚洲高清一区二区三区 | 日本精品视频在线观看 | 欧美日韩一区在线观看 | 色综合一区二区 | 精品欧美乱码久久久久久1区2区 | 青青草社区| 精彩视频一区二区三区 |