作者:c33454059 | 来源:互联网 | 2023-09-04 17:44
ASP.NET控件设计时支持之自动格式设置是如何实现的呢?
先看个图
)]
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; } } } } } 这么着效果就实现了,这次比较懒,没好好写,还想打算写别的,就先这样吧.
ASP.NET控件设计时支持之自动格式设置的相关内容就向你介绍到这里,希望对你了解ASP.NET控件设计时支持之自动格式设置有帮助。