2

继承的控件System.Web.UI.WebControls.WebControl有一个名为Font. 类型是System.Web.Ui.WebControls.FontInfo

在设计器中使用这些控件时,它会将Font属性分解为多个属性,例如Font-BoldFont-Italic等。在代码隐藏中使用这些相同的 Web 控件时,只有一个Font属性(没有Font-BoldFont-Italic等)。

创建 WebControl 时如何手动重新创建此行为?具体来说,哪些System.ComponentModel属性组合可以在 Intellisense 中显示/隐藏这些属性?

4

3 回答 3

1

您应该能够访问 Bold、Italic 等作为布尔属性:

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();

  }
于 2010-06-25T13:01:21.397 回答
1

属性分解是自动发生的。

如果您有一个控件,该控件的属性具有自己的属性

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; }
}

您可以在 aspx 中使用 Font-Bold 语法,这意味着

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

将按预期工作。但是,自动完成不起作用,我不确定需要哪种System.ComponentModel属性组合才能使其表现得像 Font-Bold。

于 2010-06-25T15:15:37.273 回答
0

您要扩展的属性(Font在本例中)应将属性System.ComponentModel.DesignerSerializationVisibility设置为System.ComponentModel.DesignerSerializationVisibility.Content. 这在以下链接中有详细说明

System.ComponentModel.DesignerSerializationVisibility

于 2010-06-28T13:35:28.993 回答