Analysis on automatic format settings supported during ASP. NET Control Design

Source: Internet
Author: User

How is automatic format settings supported by ASP. NET controls designed?

First look at a chart

 

I believe everyone is familiar with it. We can use this Panel to use the predefined style. We can call it automatic format setting or automatic style apply.

The ControlDesigner class provides the AutoFormats attribute, which provides the DesignerAutoFormatCollection set of the DesignerAutoFormat class. Let's take a look at the related classes.

 

ASP. in the automatic format settings supported by the. NET control during design, DesignerAutoFormat is a base class. If you want to provide the Formatting Function for your control during design, you can derive from this class, you must implement the Apply method, which sets the style of the associated control. since the implementation is relatively simple, there will be no more, let's look at the MSDN example directly. note that SupportsPreviewControl metadata is added to IndentLabelDesigner to support preview.

 
 
  1. [Designer(typeof(IndentLabelDesigner)),  
  2.       ToolboxData("﹤{0}:IndentLabel Runat=\"server\"﹥﹤/{0}:IndentLabel﹥")]  
  3.   public class IndentLabel : Label  
  4.   {  
  5.       [SupportsPreviewControl(true)]  
  6.       public class IndentLabelDesigner : LabelDesigner  
  7.       {  
  8.           private DesignerAutoFormatCollection _autoFormats = null;  
  9.  
  10.           public override DesignerAutoFormatCollection AutoFormats  
  11.           {  
  12.               get 
  13.               {  
  14.                   if (_autoFormats == null)  
  15.                   {  
  16.                       _autoFormats = new DesignerAutoFormatCollection();  
  17.                       _autoFormats.Add(new IndentLabelAutoFormat("MyClassic"));  
  18.                       _autoFormats.Add(new IndentLabelAutoFormat("MyBright"));  
  19.                       _autoFormats.Add(new IndentLabelAutoFormat("Default"));  
  20.                   }  
  21.                   return _autoFormats;  
  22.               }  
  23.           }  
  24.       }  
  25.  
  26.       private class IndentLabelAutoFormat : DesignerAutoFormat  
  27.       {  
  28.           public IndentLabelAutoFormat(string name)  
  29.               : base(name)  
  30.           { }  
  31.  
  32.           public override void Apply(Control inLabel)  
  33.           {  
  34.               if (inLabel is IndentLabel)  
  35.               {  
  36.                   IndentLabel ctl = (IndentLabel)inLabel;  
  37.  
  38.                   
  39.                   if (this.Name == "MyClassic")  
  40.                   {  
  41.                        
  42.                       ctl.ForeColor = Color.Gray;  
  43.                       ctl.BackColor = Color.LightGray;  
  44.                       ctl.Font.Size = FontUnit.XSmall;  
  45.                       ctl.Font.Name = "Verdana,Geneva,Sans-Serif";  
  46.                   }  
  47.                   else if (this.Name == "MyBright")  
  48.                   {  
  49.                        
  50.                       this.Style.ForeColor = Color.Maroon;  
  51.                       this.Style.BackColor = Color.Yellow;  
  52.                       this.Style.Font.Size = FontUnit.Medium;  
  53.                       ctl.MergeStyle(this.Style);  
  54.                   }  
  55.                   else 
  56.                   {  
  57.                       ctl.ForeColor = Color.Black;  
  58.                       ctl.BackColor = Color.Empty;  
  59.                       ctl.Font.Size = FontUnit.XSmall;  
  60.                   }  
  61.               }  
  62.           }  
  63.       }  
  64.   } 

The effect is achieved. This time it is relatively lazy, not well written, and I want to write something else. Let's do it first.

This section describes the content related to automatic format settings supported by ASP. NET controls during design. It is helpful to understand the automatic format settings supported by ASP. NET controls during design.

  1. Summary of ASP. NET control development
  2. Development of ASP. NET template controls
  3. Development of ASP. NET data binding controls
  4. Analysis of ASP. NET control design support
  5. Usage of ASP. NET2.0 data source controls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.