-
Notifications
You must be signed in to change notification settings - Fork 736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can anyone have work in saving a panel layouts? like there's a default view and there is a custom view of panel layout and it can saved, so if you open the application, the last view saved will be the panel layout view #700
Comments
You can save your layout in your main Form's OnFormClosing this way: protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
if (!e.Cancel)
{
// Save to Windows registry -- you can also use file or any other Stream type
using (MemoryStream stream = new MemoryStream())
{
dockPanel_.SaveAsXml(stream, System.Text.Encoding.UTF8);
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(Program.RegistryPath))
{
if (key != null)
key.SetValue("DockPanelConfig", stream.ToArray());
}
}
}
} ...an then restore it in OnLoad: protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
bool configLoaded = false;
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(Program.RegistryPath))
{
if (key != null)
{
byte[] config = key.GetValue("DockPanelConfig", null) as byte[];
if (config != null)
{
dockPanel_.SuspendLayout(true);
try
{
using (MemoryStream stream = new MemoryStream(config, false))
{
dockPanel_.LoadFromXml(stream, delegate (string persistString)
{
// Map serialized type name to actual instance
if (persistString == typeof(OutputForm).ToString())
return outputForm_;
else if (persistString == typeof(ErrorListForm).ToString())
return errorListForm_;
// Add the rest of your docking items here...
else
return null;
});
configLoaded = true;
}
}
catch (SystemException)
{
configLoaded = false;
}
finally
{
dockPanel_.ResumeLayout(true, true);
}
}
}
}
if (!configLoaded)
{
// Set the default layout
outputForm_.Show(dockPanel_);
errorListForm_.Show(dockPanel_);
//...
}
} |
@pmprochen, Thank you for helping out. I will try this |
I have successfully save an xml file but when im trying to load the xml, it will show the layout in 0.1 seconds and close again, its like a white shadow but the layout from what i save is correct, I just need to load the dockcontent and controls inside it properly. Can anyone help me to fix this issue? Its a big help private void SaveLayout(string fileName)
|
No description provided.
The text was updated successfully, but these errors were encountered: