继承 System.Web.UI.WebControls.WebControl
的控件有一个名为 Font
的属性。类型是 System.Web.Ui.WebControls.FontInfo
。
在设计器中使用这些控件时,它会将 Font
属性分解为多个属性,例如 Font-Bold
、Font-Italic
等。在代码隐藏中使用这些相同的 WebControl 时,只有一个 Font
属性(没有 Font-Bold
、Font-Italic
等).
如何在创建 WebControl 时手动重新创建此行为?具体来说,System.ComponentModel
属性的哪些组合可以在 Intellisense 中显示/隐藏这些属性?
最佳答案
您应该能够访问粗体、斜体等作为 bool 属性:
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();
}
关于c# - 重新创建 "Font"属性行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3118142/