「フォント」プロパティの動作を再現します
-
29-09-2019 - |
質問
継承するコントロール System.Web.UI.WebControls.WebControl
呼ばれるプロパティがあります Font
. 。タイプはです System.Web.Ui.WebControls.FontInfo
.
デザイナーのこれらのコントロールを使用すると、 Font
のような複数のプロパティへのプロパティ Font-Bold
, Font-Italic
, 、など。CodeBehindでこれらの同じWebControlを使用すると、 Font
プロパティ(いいえ Font-Bold
, Font-Italic
, など)。
WebControlsを作成するとき、この動作を手動で再現するにはどうすればよいですか?具体的には、どのような組み合わせ System.ComponentModel
属性は、これらのプロパティをIntellisenseで表示/非表示にできますか?
解決 3
拡張したいプロパティ(Font
この場合、属性が必要です System.ComponentModel.DesignerSerializationVisibility
に設定 System.ComponentModel.DesignerSerializationVisibility.Content
. 。これについては、次のリンクで詳しく説明しています
他のヒント
ブール特性として、太字、イタリックなどにアクセスできるはずです。
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();
}
プロパティブレークダウンは自動的に行われています。
独自のプロパティを持つプロパティを持っているコントロールがある場合
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のフォントボールド構文を使用できます。つまり、
<cc:ServerControl1 runat="server" ID="scOne"
Composite-ItemOne="true" Composite-ItemTwo ="stringx"/>
予想通りに機能します。ただし、AutoCompleteは機能しません。 System.ComponentModel
属性は、フォントボールドのように動作させるために必要です。