Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

WorkspaceManager.SaveWorkspace(String, Stream, Boolean) Method

Saves a workspace from the WorkspaceManager.Workspaces collection to a stream.

Namespace: DevExpress.Utils

Assembly: DevExpress.Utils.v24.2.dll

#Declaration

public bool SaveWorkspace(
    string name,
    Stream stream,
    bool createIfNotExisting = false
)

#Parameters

Name Type Description
name String

The name of the target workspace in the WorkspaceManager.Workspaces collection.

stream Stream

The stream to which the target workspace is to be saved.

#Optional Parameters

Name Type Default Description
createIfNotExisting Boolean False

true to capture and then save the current controls’ layouts to a stream if the WorkspaceManager.Workspaces collection does not contain a workspace with the specified name.false to interrupt the workspace saving if the WorkspaceManager.Workspaces collection does not contain a workspace with the specified name.

#Returns

Type Description
Boolean

true if the workspace was successfully saved; otherwise, false.

#Example

The following code shows how to use the WorkspaceManager component to save the form’s bounds and state, and the layout of DevExpress controls when a form is closed, and load this layout when the form starts.

You may need to call the controls’ ForceInitialize methods (e.g., GridControl.ForceInitialize) before applying layouts to the controls in a Form.Load event handler.

 string file = "layout.xml";
 string workspaceName1 = "MyLayout";

 private void Form1_Load(object sender, EventArgs e) {
     //Use the WorkspaceManager to handle the layout of DevExpress controls that reside within the current form.
     workspaceManager1.TargetControl = this;

     // Save & restore the form's size, position and state along with DevExpress controls' layouts.
     workspaceManager1.SaveTargetControlSettings = true;

     // Disable layout load animation effects 
     workspaceManager1.AllowTransitionAnimation = DevExpress.Utils.DefaultBoolean.False;

    // Disable (de)serialization for the following controls (if required):
    //WorkspaceManager.SetSerializationEnabled(gaugeControl1, false);
    //WorkspaceManager.SetSerializationEnabled(accordionControl1, false);

    // When restoring layouts of controls in a Form.Load event handler,
    // you may need to call the controls' ForceInitialize methods to finish their initialization before restoring their layouts.
    //gridControl1.ForceInitialize();
    //dockManager1.ForceInitialize();
    //barManager1.ForceInitialize();
    //...

     //Load DevExpress controls' layouts from a file
     if (workspaceManager1.LoadWorkspace(workspaceName1, file, true))
         workspaceManager1.ApplyWorkspace(workspaceName1);
 }

 private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
     //Save DevExpress controls' layouts to a file
     workspaceManager1.CaptureWorkspace(workspaceName1, true);
     workspaceManager1.SaveWorkspace(workspaceName1, file, true);
 }
See Also