Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the automatic formatting supported by ASP.NET control at design time

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how automatic formatting supported by ASP.NET controls is implemented at design time. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Look at a picture first.

I believe everyone is familiar with it, we can use this panel to use the predetermined style. We can call it automatic formatting or automatic styling.

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

ASP.NET control design support automatic formatting DesignerAutoFormat is a base class, if you want to provide formatting function for your control at design time, you can derive from this class, you must implement the Apply method, which will style the associated control. Since the implementation is relatively simple, there is no more, so just take the example of MSDN. Pay attention to adding SupportsPreviewControl metadata to IndentLabelDesigner to support the preview function.

[Designer (typeof (IndentLabelDesigner)), ToolboxData ("< {0}: IndentLabel Runat=\" server\ "> < / {0}: IndentLabel >")] public class IndentLabel: Label {[SupportsPreviewControl (true)] public class IndentLabelDesigner: LabelDesigner {private DesignerAutoFormatCollection _ autoFormats = null Public override DesignerAutoFormatCollection AutoFormats {get {if (_ autoFormats = = null) {_ autoFormats = new DesignerAutoFormatCollection (); _ autoFormats.Add (new IndentLabelAutoFormat ("MyClassic")) _ autoFormats.Add (new IndentLabelAutoFormat ("MyBright")); _ autoFormats.Add (new IndentLabelAutoFormat ("Default"));} return _ autoFormats } private class IndentLabelAutoFormat: DesignerAutoFormat {public IndentLabelAutoFormat (string name): base (name) {} public override void Apply (Control inLabel) {if (inLabel is IndentLabel) {IndentLabel ctl = (IndentLabel) inLabel If (this.Name = = "MyClassic") {ctl.ForeColor = Color.Gray; ctl.BackColor = Color.LightGray; ctl.Font.Size = FontUnit.XSmall Ctl.Font.Name = "Verdana,Geneva,Sans-Serif";} else if (this.Name = = "MyBright") {this.Style.ForeColor = Color.Maroon; this.Style.BackColor = Color.Yellow This.Style.Font.Size = FontUnit.Medium; ctl.MergeStyle (this.Style);} else {ctl.ForeColor = Color.Black; ctl.BackColor = Color.Empty Ctl.Font.Size = FontUnit.XSmall;}}

The effect was achieved. I was lazy this time. I didn't write well. I wanted to write something else. Let's do it first.

Thank you for reading! On the "ASP.NET control design support for automatic formatting is how to achieve" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report