[英]Initializing custom class in settings file
在我的WinForms C#應用程序中,我試圖將自定義類保存在設置文件中。 這是我當前的代碼:
public class PanelSaver : ApplicationSettingsBase
{
private DockingStyle ds;
System.Drawing.Point location;
System.Drawing.Size panelSize;
[UserScopedSetting()]
[SettingsSerializeAs(System.Configuration.SettingsSerializeAs.Xml)]
public DockingStyle Style
{
get { return ds; }
set { ds = value; }
}
public System.Drawing.Point Location
{
get { return location; }
set { location = value; }
}
public System.Drawing.Size Size
{
get { return panelSize; }
set { panelSize = value; }
}
}
DockingStyle變量來自DevExpress Dockpanels。
以下是“設置”文件中使用的對象:
當我嘗試使用這些變量時,請將它們傳遞給此函數:
private void DockPanelSave(PanelSaver savingPanel, DockPanel realDockingPanel)//
{
try
{
savingPanel.Location = realDockingPanel.Location;
savingPanel.Size = realDockingPanel.Size;
savingPanel.Style = realDockingPanel.Dock;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
throw new NotSupportedException("You may have added a new panel, and may not have added a corresponding " +
"settings variable to hold it in the Settings.settings file");
}
}
我得到一個空錯誤。
我應該如何初始化設置文件中的值? 我猜想我需要放入某種XML,但是我不知道生成該XML的正確步驟。 關於此錯誤或其他原因導致我的null錯誤的任何指示,我們將不勝感激
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.