2

を継承するコントロールにSystem.Web.UI.WebControls.WebControlは、 というプロパティがありますFont。タイプはSystem.Web.Ui.WebControls.FontInfo.

デザイナーでこれらのコントロールを操作する場合、プロパティは 、 などの複数のプロパティFontに分割されます。コード ビハインドでこれらの同じ WebControls を操作する場合、プロパティ (no 、など) しかありません。Font-BoldFont-ItalicFontFont-BoldFont-Italic

WebControls を作成するときに、この動作を手動で再現するにはどうすればよいですか? 具体的にはSystem.ComponentModel、Intellisense でこれらのプロパティを表示/非表示にできる属性の組み合わせは何ですか?

4

3 に答える 3

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 に答える
1

ブール値のプロパティとして、太字、斜体などにアクセスできる必要があります。

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 に答える
0

展開するプロパティ (Fontこの場合) には、属性を にSystem.ComponentModel.DesignerSerializationVisibility設定する必要がありますSystem.ComponentModel.DesignerSerializationVisibility.Content。これについては、次のリンクで詳しく説明しています

System.ComponentModel.DesignerSerializationVisibility

于 2010-06-28T13:35:28.993 に答える