Main Menu
Knowledge Base
Product Registration
Log an Incident
Request a Feature
Search Incidents/Bug Reports


Search KB

Please note: In an effort to better serve you, we are in the process of restructuring DevCenter. In the process, we have moved many items that you may be used to finding in DevCenter over to the Main Site. If you are having trouble locating something, please try looking at the following places:

Knowledge Base Article: KB09847

HOWTO:NetAdvantage CAB Extensibility Kit: Loading and saving Dock Layouts with UltraDockWorkspace [PART 3]


The information in this article applies to:
CAB Extensibility Kit (vAll)
  Article Created: 
4/25/2006

Last Updated:
7/31/2007

Article Type
How To
  
Page Options
Average Rating:
6 out of 10

Rate this page
Print this page
E-mail this page
Add to Favorites

Summary

The UltraDockWorkspace provides a rich, powerful way of managing SmartParts so that end users can dock, pin, hide, show and float user interface components to their liking. This article shows how to save these customizations so that the next time the users run the application, it will be the same as the last time they closed it.

Step-By-Step Example

...Continued

Until this point, we have covered how to load a Dock layout if one exists. Now we will cover how to save a layout during the application’s use.

In a standard Windows Forms application where all of the user interface components and events are accessible from within the application, we would normally handle the main form’s FormClosing event and in this event, we can simply call the DockManager.SaveAsXML( ) method to save it easily. Due to the nature of working with CAB and the nested SmartParts and Workitems, it is not so simple to handle this situation in the same way. To handle this scenario, we can listen to the events fired by the UltraDockWorkspace whenever we make a change to its controls and then we can save the Layout. This means that whenever we pin, dock, float or resize any of the controls, we will be saving the Layout. This should not raise any concerns because it does not happen so often. If you are saving the layout as a stream and writing it to a remote database somewhere, then this may introduce some performance related issues, so as an alternative, you can always save to a file on disk and when the application closes, you can stream the file to the database just once.

Here are the UltraDockWorkspace events that are being used to save the Dock layout:

C#

        private void DockWorkspace_AfterDockChange(object sender, Infragistics.Win.UltraWinDock.PaneEventArgs e)
        {
            this.SaveDockLayout();
        }

        private void DockWorkspace_AfterToggleDockState(object sender, Infragistics.Win.UltraWinDock.PaneEventArgs e)
        {
            this.SaveDockLayout();
        }

        private void DockWorkspace_AfterSplitterDrag(object sender, Infragistics.Win.UltraWinDock.PanesEventArgs e)
        {
            this.SaveDockLayout();
        }

        private void DockWorkspace_AfterPaneButtonClick(object sender, Infragistics.Win.UltraWinDock.PaneButtonEventArgs e)
        {
            this.SaveDockLayout();
        }

        private void DockWorkspace_AfterHideFlyout(object sender, Infragistics.Win.UltraWinDock.ControlPaneEventArgs e)
        {
            this.SaveDockLayout();
        }

The actual implementation code to save the layout is as follows (for Model View Presenter, this should be implemented in the presenter, not the view):

C#

        public void SaveDockLayout()
        {
            if (File.Exists(_dock))
            {
                File.Delete(_dock);
            }
            this.DockWorkspace.SaveAsXML(_dock);
        }

Running the sample

To run the application, take the following steps:

1.    Run the application
2.    Pin, Unpin, Dock and manipulate the controls
3.    Close the application (close the window)
4.    Run the application again

Results:

Notice how the Dock Layout is maintained across different run sessions.


Review:
Now that we have learned how to load and save Dock layouts, we can incorporate this functionality into our NetAdvantage powered CAB applications. Please download the source code and review the code and comments to see this implementation in action.

Related Articles

HOWTO: NetAdvantage CAB Extensibility Kit: Loading and saving Dock Layouts with UltraDockWorkspace [PART 2] (KB09845)

HOWTO: NetAdvantage CAB Extensibility Kit: Loading and saving Dock Layouts with UltraDockWorkspace [PART 1] (KB09844)

Samples

cab_dockworkspace_loadsave_layouts.zip
 CAB Loading Saving Layouts with UltraDockWorkspace C# Sample



How would you rate the quality of this content?
Poor -----------------------------------------> Outstanding

Tell us why you rated the content this way. (optional)