具有稱爲PanelGroup的類,並且它具有名爲ElementControl的屬性,其類型爲Control。因爲我知道控制不是可序列化的,那麼有什麼建議這個類被序列化的做法?謝謝。具有基於控件的屬性的c#類序列化
public class PanelGroup
{
public PanelGroup(FormElementGroupBase parentElement) : base(parentElement)
{
Intialize();
}
public PanelGroup(FormElementGroupBase parentElement, int id, string name, bool isVertical) : base(parentElement, id, name)
{
Intialize();
IsVertical = isVertical;
}
private void Intialize()
{
this.ItemType = DomainItemTypes.PANEL_GROUP;
this.ElementControl = new PanelControl();
this.ElementControl.MinimumSize = new Size(50, 50);
(this.ElementControl as PanelControl).AutoSize = true;
(this.ElementControl as PanelControl).AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
if (ParentElement != null)
{
ParentElement.ElementControl.Controls.Add(this.ElementControl);
};
this.ElementControl.AllowDrop = true;
this.ElementControl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Control_OnMouseUp);
this.ElementControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Control_OnMouseDown);
this.ElementControl.KeyDown += new KeyEventHandler(this.Control_OnKeyDown);
this.ElementControl.DragDrop += new DragEventHandler(OnDragDrop);
this.ElementControl.DragOver += new DragEventHandler(OnDragOver);
}
[Browsable(false)]
public override string NamePrefix
{
get { return "PanelGroup"; }
}
internal sealed override void Highlight()
{
(this.ElementControl as PanelControl).Appearance.BorderColor = SelectionColor;
}
}
您的預期結果是什麼?如果序列化和反序列化一個PanelGroup對象,你是否期望ElementControl爲null?或者您是否期望將所有相關屬性設置爲匹配預序列化值? –