重新创建“字体”属性行为
-
29-09-2019 - |
题
继承的控件 System.Web.UI.WebControls.WebControl
有一个称为的财产 Font
. 。类型是 System.Web.Ui.WebControls.FontInfo
.
在设计人员中使用这些控件时,它会破坏 Font
属性属于多个属性 Font-Bold
, Font-Italic
, 等等。在使用CodeBehind中使用这些相同的网络控制时,只有一个 Font
属性(否 Font-Bold
, Font-Italic
, , ETC)。
创建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"/>
将按预期工作。但是,自动完成不起作用,我不确定哪种组合 System.ComponentModel
需要属性才能使其表现得像字体形状。
不隶属于 StackOverflow