using System; using System.Web.UI; using System.Web.UI.Design; using System.Web.UI.WebControls; using System.ComponentModel; using System.ComponentModel.Design; namespace WebControlDesignerExample ...{ // This control designer offers designer verb menu commands // that can alter the design time html provided for the // System.Web.UI.Control this designer supports. publicclass TextSizeWebControlDesigner : System.Web.UI.Design.ControlDesigner ...{ // Whether to display the html of the associated // control using a large heading text size. privatebool LargeText; public TextSizeWebControlDesigner() : base() ...{ LargeText =false; } // Provides a menu command to toggle the text size. publicoverride System.ComponentModel.Design.DesignerVerbCollection Verbs ...{ get ...{ DesignerVerbCollection dvc =new DesignerVerbCollection(); if( LargeText ) dvc.Add( new DesignerVerb("Reduce text size", new EventHandler(this.toggleTextSize)) ); else dvc.Add( new DesignerVerb("Enlarge text size", new EventHandler(this.toggleTextSize)) ); return dvc; } } // Returns the html to use to represent the control at design time. publicoverridestring GetDesignTimeHtml() ...{ string html =base.GetDesignTimeHtml(); if( LargeText ) return"<H1>"+html+"</H1>"; else return"<H3>"+html+"</H3>"; } // Event handler to toggle whether the html receives a large or // small size heading markup tag. privatevoid toggleTextSize(object sender, EventArgs e) ...{ if( LargeText ) LargeText =false; else LargeText =true; this.IsDirty =true; this.UpdateDesignTimeHtml(); } } // Simple text web control renders a text string. // This control is associated with the TextSizeWebControlDesigner. [DesignerAttribute(typeof(TextSizeWebControlDesigner), typeof(IDesigner))] publicclass TextControl : System.Web.UI.WebControls.WebControl ...{ privatestring text; [Bindable(true), Category("Appearance"), DefaultValue("")] publicstring Text ...{ get ...{ return text; } set ...{ text = value; } } public TextControl() ...{ text ="Test phrase"; } protectedoverridevoid Render(HtmlTextWriter output) ...{ output.Write(Text); } } }