重新创建“字体”财产行为

发布于 2024-09-06 20:36:22 字数 465 浏览 15 评论 0原文

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

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九厘米的零° 2024-09-13 20:36:22

您应该能够以布尔属性的形式访问粗体、斜体等:

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

  }

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

  }
甜味拾荒者 2024-09-13 20:36:22

财产崩溃是自动发生的。

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

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。

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.

笔落惊风雨 2024-09-13 20:36:22

您要扩展的属性(本例中为 Font)应将属性 System.ComponentModel.DesignerSerializationVisibility 设置为 System.ComponentModel.DesignerSerializationVisibility.Content< /代码>。以下链接详细介绍了

System.ComponentModel.DesignerSerializationVisibility

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文