We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Finer control over docking

Thread ID:

Created:

Updated:

Platform:

Replies:

118839 Apr 14,2015 09:44 AM Apr 20,2015 10:25 AM Windows Forms 7
loading
Tags: DockingManager
Sergei Leschinksy
Asked On April 14, 2015 09:44 AM

Hi, let's assume that there are two docking panels added to the form one with Left and one with Right alignment. Now we need to add a third panel at the bottom. There are 2 possible layouts:
1) third panel is between first two;
|   |
|--|

2) third panel is below first two;
|    |
----

With interactive docking (i.e. with mouse) it's easy to choose between these 2 layouts by choosing the button at the center of the form or at the bottom. But how to do it in code? From my testing the layout depends on the order in which I add panels:

// here are 3 panels
dockingManager1.SetEnableDocking(gradientPanel1, true);
dockingManager1.SetEnableDocking(gradientPanel2, true);
dockingManager1.SetEnableDocking(gradientPanel3, true);

// first layout: third panel will be between first 2 
dockingManager1.DockControl(gradientPanel1, this, DockingStyle.Left, 150);
dockingManager1.DockControl(gradientPanel2, this, DockingStyle.Right, 150);
dockingManager1.DockControl(gradientPanel3, this, DockingStyle.Bottom, 150);

// second layout: third panel will be below first 2
dockingManager1.DockControl(gradientPanel3, this, DockingStyle.Bottom, 150);
dockingManager1.DockControl(gradientPanel1, this, DockingStyle.Left, 150);
dockingManager1.DockControl(gradientPanel2, this, DockingStyle.Right, 150);

Now the problem is I have an application with plugins, which add docking panels dynamically. I can't determine what plugins the user will choose and therefore in what order dock panels will be added. But I need to have some control over the resulting layout, i.e. to choose between 2 options described above. Is there a way to do it? 

Thanks,
Sergei

Saravanan T [Syncfusion]
Replied On April 15, 2015 01:38 PM

Hi Sergei,

Thank you for using Syncfusion products.

We are unable to understand this requirement clearly. We hope that, this reported requirement is to modify the docked control alignment on specific cases. So could you please let us know, in what kind of cases docked control alignment needs to be modified?

Otherwise could you please share us more details about this reported requirement? So that we can analyze and provide a prompt solution as earlier as possible.

Please let us know if you need any further assistance.

Regards,
Saravanan T

Sergei Leschinksy
Replied On April 15, 2015 05:46 PM

Thanks for the answer. Ok, I'll try to make the task more clear. 

There are 2 dock panels at the left and at the right of the form. I need to add programmatically  the third one and dock it to the bottom of the form BELOW the first two.  I attach screenshots with initial state (docking1.png) and expected result after pressing a button (docking2.png). With my current code I can only achieve the layout shown at the docking3.png (third panel BETWEEN the first 2). Once again it should be done in code, not in a designer, since I need to add panels dynamically in my app. Hope it's more clear this time.

Here is the code:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            dockingManager1.SetEnableDocking(panel1, true);
            dockingManager1.SetEnableDocking(panel2, true);
            
            dockingManager1.DockControl(panel1, this, DockingStyle.Left, 150);
            dockingManager1.DockControl(panel2, this, DockingStyle.Right, 150);
        }

        private void buttonAdv1_Click(object sender, EventArgs e)
        {
            dockingManager1.SetEnableDocking(panel3, true);

            // this will add the panel BETWEEN the first 2, how to add it BELOW them?
            dockingManager1.DockControl(panel3, this, DockingStyle.Bottom, 150);
        }
    }

Thanks,
Sergei


Attachment: docking_27ed8ae8.zip

Ashwini Jaya Preetha Durai Samy [Syncfusion]
Replied On April 16, 2015 08:46 AM

Hi Sergei,

 

Thank you for your update.

 

In Docking Manager, controls dock alignment will be specified based on available space in Parent Form. So it is needed for user, to specify the dock alignment based on requirement.

 

For Example:

 

Based on this reported case, user need to dock panel at the bottom position of parent form, where already two panels are docked in right and left alignment.

 

So as we have explained, when setting dock alignment for Panel 3 at the bottom, it will be occupied only in remaining space of parent form. And to dock the Panel 3 at bottom of the parent form, it is needed for user to rearrange docking alignment. Please make use of below code snippet for your reference.

 

Code snippet[C#]:

 

        private void button1_Click(object sender, EventArgs e)

        {

            dockingManager1.SetEnableDocking(panel3, true);

            dockingManager1.DockControl(panel3, this, DockingStyle.Bottom, 150); 

 

            //Re docking the panels.

            dockingManager1.DockControl(panel1, this, DockingStyle.Left, 150);

            dockingManager1.DockControl(panel2, this, DockingStyle.Right, 150);

          

        }

 

We have also prepared sample for your reference and it can be downloaded from below location.

 

Sample location: http://www.syncfusion.com/downloads/support/forum/118839/DockingWindowsSample-855746010.zip

 

Could you please look into the sample and kindly let us know if it helps? Otherwise please share us more details about this requirement. So that we can analyze and provide prompt solution as earlier as possible.

 

Please let us know if you need any further assistance,

 

Regards,

Ashwini


Sergei Leschinksy
Replied On April 16, 2015 11:45 AM

Thanks Ashwini, 

it's a step in a right direction. Indeed I can dock the third panel and then redock the first 2. The problem is how to know the layout of the existing panels. In this example there are only 2 panels but in reality I have 7 of them even at this stage of development and it can be even more. 

The closest thing I got on this in KB is this article: http://www.syncfusion.com/kb/1050/how-to-get-set-the-docking-state-for-a-docked-control-on-loading-the-application

I tried to implement it, but got problem with capturing screen rectangle for existing panels. 
- DockInfo.rcDockArea suggested in the article often doesn't return correct X, Y values - for example it returns (0, 0) for the right panel in your sample; 
- DockHostController.LayoutRect returns correct screen rectangle for visible panels, but it doesn't work invisible ones, i.e. those with DockingManager.SetDockVisibility(ctrl, false));

Is there a precise method to retrieve layout of existing panels which works also for hidden and autohidden panels? 

Here is the code I used.

private void CaptureLayout()
{
    foreach (var p in GetPanels())
    {
        var host = p.Parent as DockHost;
        var controller = host.InternalController as DockHostController;
        DockInfo di = controller.GetSerCurrentDI();

        // this rect is often incorrect (X = 0, Y = 0; when they shouldn't be)
        var r = di.rcDockArea;

        // this one returns correct rectangle for visible panels; 
        // but doesn't work for hidden or autohidden ones
        // r = controller.LayoutRect;

        Debug.Print("Style: " + di.dStyle);
        Debug.Print("x: {0}; y: {1}; w: {2}; h: {3}", r.X, r.Y, r.Width, r.Height);
    }
}

private IEnumerable<Control> GetPanels()
{
    var enumerator = dockingManager1.Controls;
    enumerator.Reset();
    while (enumerator.MoveNext())
    {
        var dockItem = enumerator.Current as Control;
        if (dockItem != null)
        {
            yield return dockItem;
        }
    }
}

Thanks,
Sergei

Saravanan T [Syncfusion]
Replied On April 18, 2015 09:27 AM

Hi Sergei,

Thank you for your update.

Query 1 : How to detect the docked bounds of hidden and visible control using LayoutRect in Docking Manager?

We are able to calculate the bounds of both visible and invisible docked controls by using property named “LayoutRect” in DockHostController. Could you please check with the sample and video attached in below location.

Sample Location: http://www.syncfusion.com/downloads/support/forum/118839/Docking_test617866673.zip

Video Location: http://www.syncfusion.com/downloads/support/forum/118839/DockingWindows2021599930.zip

Query 2: Incorrect information in our documentation links?

We would like to thank you for notifying this case. We have notified our documentation team about this case and it will be modified as earlier as possible.

Query 3: Problem with AutoHidden control bounds?

In Docking Manager, docked controls LayoutRect value will be calculated, based on its docked control bounds and parent form bounds. So once control is set to Auto Hidden, its bounds will be updated to default Auto Hidden bounds. Hence for AutoHidden control, default bounds will be returned.

Please let us know if you need any further assistance.

Regards,
Saravanan T


Sergei Leschinksy
Replied On April 18, 2015 12:36 PM

Thanks, for the update. 

DockHostController.LayoutRect indeed returns correct values for hidden panels. I must have missed that. DockHostController.DINew.rcDockArea can be used to get values for auto-hidden panels. So potentially it can work, but it's hardly a production quiality solution, since hidden / autohidden rectangles remain unchanged after the panels were last visible, while user can resize other panels after that.  In some cases it won't be possible to correctly restore layout because of this. Making it 100% correct most likely requires delving even deeper in the underlying classes.  I leave it here for now.

Since there is no easy solution for my scenario, I would like to submit a request for the new API method:

DockingManager.DockControlToOuterBorder(Control control, DockingStyle dockingStyle, int size);       // no need to pass parent since DockingManager obviously knows its parent

I attach a screenshot with explanation.

Thanks,
Sergei



Attachment: DockControlToOuterBorder_4bff7898.zip

Senthil Kumaran Rajan [Syncfusion]
Replied On April 20, 2015 10:25 AM

Hi Sergei,

Thank you for your update.

As we have explained in our previous update, at present DockingManager doesn’t have the support for reported requirement. We have created a support incident under your account, to track the status of this requirement. Please log on to our support website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents

Regards,
Senthil


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;