Creating and managing docking windows dynamically
|
Article relates to
|
RadDock for WinForms
|
|
Created by
|
Julian Benkov, Telerik
|
|
Last modified
|
June 1, 2007
|
|
Last modified by
|
Julian Benkov, Telerik
|
HOW-TO
Create and manage docking windows dynamically
SOLUTION
A basic problem related to DockingManager is how to restore saved dock layout and it's content of inner controls hosted in DockPanel and DocumentPane windows.
The solution is to restore dynamically the windows using the GUID provided for the IDockable window from its ID - property:
| public partial class MainForm : Form |
| { |
| private ReportDataSet.ReportTableDataTable reports = new ReportDataSet.ReportTableDataTable(); |
| |
| public MainForm() |
| { |
| InitializeComponent(); |
| } |
| |
| private void MainForm_Load(object sender, EventArgs e) |
| { |
| |
| #if Init |
| ReportDockForm form = new ReportDockForm(); |
| form.Text = "Report 1"; |
| form.ReportContent = "Report 1 Content!!!"; |
| |
| dockingManager.SetDocument(form); |
| |
| form = new ReportDockForm(); |
| form.Text = "Report 3"; |
| form.ReportContent = "Report 3 Content!!!"; |
| |
| dockingManager.SetDocument(form); |
| |
| form = new ReportDockForm(); |
| form.Text = "Report 2"; |
| form.ReportContent = "Report 2 Content!!!"; |
| |
| dockingManager.SetDocument(form); |
| #else |
| |
| try |
| { |
| dockingManager.LoadXML(Application.StartupPath + "\\dock.cfg"); |
| |
| reports.ReadXml(Application.StartupPath + "\\reports.rpt"); |
| for (int i = 0; i < reports.Count; i++) |
| { |
| ReportDockForm dockForm = GetDocumentForm(reports[i].DockGuid); |
| if (dockForm != null) |
| { |
| dockForm.Text = reports[i].Name; |
| dockForm.ReportContent = reports[i].Content; |
| } |
| } |
| } |
| catch { } |
| |
| #endif |
| |
| |
| } |
| |
| private ReportDockForm GetDocumentForm(string guid) |
| { |
| for (int i = 0; i < dockingManager.Documents.Count; i++) |
| { |
| if(dockingManager.Documents[i].ID.ToString() == guid) |
| { |
| return dockingManager.Documents[i] as ReportDockForm; |
| } |
| } |
| |
| return null; |
| } |
| |
| private void MainForm_FormClosing(object sender, FormClosingEventArgs e) |
| { |
| reports.Clear(); |
| for (int i = 0; i < dockingManager.Documents.Count; i++) |
| { |
| ReportDockForm dockForm = dockingManager.Documents[i] as ReportDockForm; |
| if(dockForm != null) |
| { |
| ReportDataSet.ReportTableRow row = reports.NewReportTableRow(); |
| row.DockGuid = dockForm.ID.ToString(); |
| row.Name = dockForm.Text; |
| row.Content = dockForm.ReportContent; |
| reports.AddReportTableRow(row); |
| } |
| } |
| reports.AcceptChanges(); |
| |
| reports.WriteXml(Application.StartupPath + "\\reports.rpt"); |
| |
| dockingManager.SaveXML(Application.StartupPath + "\\dock.cfg"); |
| } |
}
|
sample business object:
| public class ReportDockForm : UserDockForm |
| { |
| private RichTextBox rtf = new RichTextBox(); |
| |
| public ReportDockForm() |
| { |
| rtf.Dock = DockStyle.Fill; |
| this.Controls.Add(rtf); |
| } |
| |
| public string ReportContent |
| { |
| get { return rtf.Text; } |
| set { rtf.Text = value; } |
| } |
| } |
Comments
If you'd like to comment on this KB
article, please, send us a
Support Ticket.
Thank you!
Please
Sign In
to rate this article.