This is a migrated thread and some comments may be shown as answers.

How to get dock position of a window

11 Answers 636 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 19 Feb 2010, 06:14 PM
I dock a form using this code:

            Form2 frm2 = new Form2();
            this.radDock1.DockControl(frm2, DockPosition.Left);
            frm2.Show();

            

Later on I need to know where a given window is docked.  I can get the host window object like so:

HostWindow hostWin = this.radDock1.GetHostWindow(frm2);

But I see no property on HostWindow to get me the DockPosition attribute.  I can only tell if the window is docked or floating.  

11 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 22 Feb 2010, 12:27 PM
Hi Gary,

Thank you for the question.

A DockWindow does not have a DockPosition property, because DockWindows may be arranged in a docking hierarchy (you can dock a DockWindow to a position, passing another DockWindow as a base anchor) and such property value would be inaccurate without knowing the value of the base anchor as well.

Could you please share with me the scenario where you need to take the DockPosition value? This will allow us to think of an implementation that will best suit your needs.

I am looking forward to your response.

Greetings,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Gary
Top achievements
Rank 1
answered on 22 Feb 2010, 07:32 PM
We're using telerik controls to modernize an existing application architecture, which has an existing API which allows users to dock forms by simply calling a method, passing the form, and the desired dock orientation.  They could later query the dock position by passing in the form.  I need to support that same API with telerik docking.  We don't really care if the window happens to be docked inside another dock window, just that we can get the dock orientation relative to it's container.  
0
Nikolay
Telerik team
answered on 25 Feb 2010, 01:44 PM
Hi Gary,

Judging by your description, I think that you need the GetAutoHidePosition method which returns the position of a DockWindow relative to the RadDock control (the main container):
Type type = typeof(RadDock);
MethodInfo method = type.GetMethod("GetAutoHidePosition", BindingFlags.Instance | BindingFlags.NonPublic);
object o = method.Invoke(this.radDock1, new object[] { (ToolTabStrip)this.radDock1["MHM"].TabStrip });
AutoHidePosition position = (AutoHidePosition)o;
this.Text = position.ToString();

However, if you want to get the position of a DockWindow relative to its base anchor, you can do it as it is demonstrated below. Please note that in this case you should pass not only the ToolTabStrip of the ToolWindow of interest, but the anchor ToolTabStrip as well:
public DockPosition GetDockPositionFromAnchor(ToolTabStrip tabStrip, ToolTabStrip anchorStrip)
{
    RadSplitContainer container = tabStrip.SplitContainer;
  
    int tabStripPanelIndex = container.SplitPanels.IndexOf(tabStrip);
    int anchorStripPanelIndex = container.SplitPanels.IndexOf(anchorStrip);
  
    if (tabStrip.SplitContainer.Orientation == Orientation.Vertical)
    {
        if (tabStripPanelIndex > anchorStripPanelIndex)
        {
            return DockPosition.Right;
        }
        else
        {
            return DockPosition.Left;
        }
    }
    else
    {
        if (tabStripPanelIndex < anchorStripPanelIndex)
        {
            return DockPosition.Top;
        }
        else
        {
            return DockPosition.Bottom;
        }
    }
}

You can call the method like this:
GetDockPositionFromAnchor((ToolTabStrip)toolWindow5.TabStrip, (ToolTabStrip)toolWindow4.TabStrip)

I hope this helps. If you have additional questions, feel free to contact me.

Kind regards,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Gary
Top achievements
Rank 1
answered on 26 Feb 2010, 07:16 PM
So if all I have is a host window object, I know how to get it's TabStrip property.  But how would I get the "anchorStrip" object for that particular window?  For example, here's all the information I have (at the time I need to get the dock position):

HostWindow hostWin = this.radDock1.GetHostWindow(frm2);

How would I call your GetDockPositionFromAnchor method to get it's position?


0
Nikolay
Telerik team
answered on 04 Mar 2010, 08:44 AM
Hello Gary,

Thank you for getting back to me.

This is the reason I mentioned that a DockPosition value will be irrelevant without knowing the anchor TabStrip value. When you dock a window setting another window as a base anchor, all RadDock does is place the window in the appropriate TabStrip. However, no further information is kept for the base anchor of this window and its tabstrip.

Could you please share with us what will be determined by the DockPosition value that you want to query? How will this affect your application? This information will help us to think of a more suitable approach if such can be implemented. Generally, if you only dock windows programmatically, you can save the DockPosition in the Tag property of the HostWindow.

Best wishes,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Bill
Top achievements
Rank 1
answered on 13 Sep 2010, 03:25 PM
Hi Nikolay:

I used your example code to get the position of a tool window that the user has docked and autohidden to the bottom of the RadDock.  Unfortunately this method always returns "Left".  Can you tell me if I have the parameters wrong or something?
Type type = typeof(RadDock);
MethodInfo method = type.GetMethod("GetAutoHidePosition", BindingFlags.Instance | BindingFlags.NonPublic);
object o = method.Invoke(toolWindow.DockManager, new object[] { (ToolTabStrip)toolWindow.TabStrip });
AutoHidePosition position = (AutoHidePosition)o;
side = position.ToString();
0
Nikolay
Telerik team
answered on 16 Sep 2010, 06:28 PM
Hi Bill,

Thank you for the question.

This code snippet concerns the TabStrip of a ToolWindow when this ToolWindow is in Docked state. However, the TabStrip property of the ToolWindow is only valid when the window is in Docked state and you should not try to work with it when it is in AutoHide mode. I am attaching a sample project which demonstrates how you can get the correct position although the window is AutoHide. Basically, you should keep the AutoHidePosition while the window is Docked and save this position in the Tag of the ToolWindow when it becomes AutoHide.

I hope this helps.

Sincerely yours,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ryan
Top achievements
Rank 1
answered on 18 Dec 2015, 04:20 AM

Nikolay,

I'm in need of a solution for this in the current version of Telerik UI for WinForms for autohidden windows. I downloaded your sample project but it doesn't seem to be working correctly anymore (it always returns left when the window is autohidden). Could you offer a different solution? I'm attempting to work around this bug.

Thanks!

0
Hristo
Telerik team
answered on 18 Dec 2015, 03:36 PM
Hi Ryan,

Thank you for writing.

I am sending you attached a project implementing the suggested by my colleague approach. It is working correctly with the latest version of the suite. 

In case you are having issues with the reported issue and the suggested workaround please open up a support ticket and send us your project.

I am sending you attached my project as well as a short animation.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Ryan
Top achievements
Rank 1
answered on 19 Dec 2015, 03:56 AM

Hristo,

Thanks for sending me that project. I wasn't thinking clearly before - I understood that it wasn't possible to obtain the DockPosition while a DockWindow was in autohide mode, but I also didn't realize that whenever a user docked a floating window, its DockState would default to 'Docked' rather than 'AutoHide', so I could just grab the DockPosition while the DockWindow was 'Docked'.

I actually submitted the suggested workaround but found that it wouldn't work if a user decided to change the DockPosition of any of the windows :)

Here's the code that I used:

Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    RadDock1.DockWindow(ToolWindow2, DockPosition.Right)
    RadDock1.AutoHideWindows(New DockWindow() {ToolWindow2}, AutoHidePosition.Right)
    ToolWindow2.Tag = DockPosition.Right
 
    RadDock1.AutoHideWindow(ToolWindow1)
    ToolWindow1.Tag = DockPosition.Left
End Sub
 
Private Sub RadDock1_FloatingWindowCreated(sender As Object, e As FloatingWindowEventArgs) Handles RadDock1.FloatingWindowCreated
    For Each dw As DockWindow In CType(sender, RadDock).DockWindows
        If dw.Handle <> CType(sender, RadDock).ActiveWindow.Handle AndAlso dw.DockState = DockState.AutoHide Then
            dw.DockState = dw.PreviousDockState
 
            RadDock1.AutoHideWindows(New DockWindow() {dw}, dw.Tag)
        End If
    Next
End Sub
 
Private Sub RadDock1_DockStateChanged(sender As Object, e As DockWindowEventArgs) Handles RadDock1.DockStateChanged
    If e.DockWindow.DockState = DockState.Docked Then
        e.DockWindow.Tag = GetDockPostition(e.DockWindow)
    End If
End Sub
 
Public Function GetDockPostition(window As DockWindow) As AutoHidePosition
    Dim type As Type = GetType(RadDock)
    Dim mi As Reflection.MethodInfo = Me.RadDock1.[GetType]().GetMethod("GetAutoHidePosition", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
    Dim res As Object = mi.Invoke(Me.RadDock1, New Object() {DirectCast(Me.RadDock1(window.Name).TabStrip, ToolTabStrip)})
    Dim aHPposition As AutoHidePosition = DirectCast(res, AutoHidePosition)
 
    Return aHPposition
End Function

0
Hristo
Telerik team
answered on 21 Dec 2015, 04:15 PM
Hi Ryan,

I am glad that you have resolved the issue. Thank you also for commenting on the feedback item and referring this thread.

Please let me know if you need additional assistance.

Regards,
Hristo Merdjanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Dock
Asked by
Gary
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Gary
Top achievements
Rank 1
Bill
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or