How to get dock position of a window

12 posts, 0 answers
  1. Gary
    Gary avatar
    30 posts
    Member since:
    Jun 2009

    Posted 19 Feb 2010 Link to this post

    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.  
  2. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 22 Feb 2010 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Gary
    Gary avatar
    30 posts
    Member since:
    Jun 2009

    Posted 22 Feb 2010 Link to this post

    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.  
  5. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 25 Feb 2010 Link to this post

    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.
  6. Gary
    Gary avatar
    30 posts
    Member since:
    Jun 2009

    Posted 26 Feb 2010 Link to this post

    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?


  7. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 04 Mar 2010 Link to this post

    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.
  8. Bill
    Bill avatar
    27 posts
    Member since:
    Oct 2008

    Posted 13 Sep 2010 Link to this post

    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();
  9. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 16 Sep 2010 Link to this post

    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
  10. Ryan
    Ryan avatar
    35 posts
    Member since:
    Jul 2015

    Posted 17 Dec 2015 Link to this post

    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!

  11. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 18 Dec 2015 Link to this post

    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
  12. Ryan
    Ryan avatar
    35 posts
    Member since:
    Jul 2015

    Posted 18 Dec 2015 in reply to Hristo Link to this post

    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

  13. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 21 Dec 2015 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready