views:

26

answers:

3

Controls that inherit off of System.Web.UI.WebControls.WebControl have a property called Font. The type is System.Web.Ui.WebControls.FontInfo.

When working with these controls in the designer, it breaks out the Font property into multiple properties like Font-Bold, Font-Italic, etc. When working with these same WebControls in the codebehind, there's only a Font property (no Font-Bold, Font-Italic, etc).

How can this behavior be manually recreated when creating WebControls? Specifically, what combination of System.ComponentModel attributes can show/hide these properties in Intellisense?

+1  A: 

You should be able to access Bold, Italic and so on as boolean properties:

http://msdn.microsoft.com/it-it/library/system.web.ui.webcontrols.fontinfo.aspx

  void Page_Load(object sender, EventArgs e)
  {
    // When the page loads, set the the myLabel Label control's FontInfo properties.
    // Note that myLabel.Font is a FontInfo object.

    myLabel.Font.Bold = true;
    myLabel.Font.Italic = false;
    myLabel.Font.Name = "verdana";
    myLabel.Font.Overline = false;
    myLabel.Font.Size = 10;
    myLabel.Font.Strikeout = false;
    myLabel.Font.Underline = true;

    // Write information on the FontInfo object to the myLabel label.
    myLabel.Text = myLabel.Font.ToString();

  }
mamoo
right. But the Font property doesn't show up in designer mode, only in the code behind. Additionally, Font-Bold, Font-Italic, etc don't show up on the code behind, only on the designer mode. I want to be able to create properties on my webcontrols that behave that way.
SAGExSDX
+1  A: 

The property-breakdown is happening automatically.

If you have a control that has a property that has properties of its own

public class ServerControl1 : WebControl
{
   public CompositeItem Composite { get; set; }

    public ServerControl1()
    {
        Composite = new CompositeItem();
    }
}

public class CompositeItem
{
    public bool ItemOne { get; set; }
    public string ItemTwo { get; set; }
    public int ItemThree { get; set; }
}

you can use the Font-Bold syntax in the aspx, meaning that

<cc:ServerControl1 runat="server" ID="scOne" 
    Composite-ItemOne="true" Composite-ItemTwo ="stringx"/>

will work as expected. However, autocomplete does not work, and I'm not sure which combination of System.ComponentModel attributes is required to make it behave like the Font-Bold.

SWeko
Ah~ I didn't know it was automatic that it would provide those extended properties. Indeed the question at this point is what combination of `System.ComponentModel` attributes would lead to the behavior found in webcontrols inheriting off of `System.Web.UI.WebControls.WebControl`
SAGExSDX
A: 

The property that you'd like to expand (Font in this case) should have attribute System.ComponentModel.DesignerSerializationVisibility set to System.ComponentModel.DesignerSerializationVisibility.Content. This is detailed in the following link

System.ComponentModel.DesignerSerializationVisibility

SAGExSDX