Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

[Question] Which DockingEdge Page is Docked on? #201

Open
fdncred opened this issue Jul 3, 2019 · 27 comments
Open

[Question] Which DockingEdge Page is Docked on? #201

fdncred opened this issue Jul 3, 2019 · 27 comments

Comments

@fdncred
Copy link

fdncred commented Jul 3, 2019

How do I tell which DockingEdge a Page is docked on? It looks like DoDragDropEnd() is part of the equation but I can't figure out where to go from here. The below code doesn't help because it always shows the edge.Edge as the DockingEdge where the page was created.

private void KryptonDockingManager_DoDragDropEnd(object sender, EventArgs e)
{
    var kPage = kryptonDockingManager.Pages.Where(x => x.Controls.ContainsKey("IndexingCtrl")).FirstOrDefault();
    var edge = kryptonDockingManager.FindDockingEdgeDocked(kPage.UniqueName);

    var flowLayoutPanel = ((IndexingCtrl)kPage.Controls[0]).GetFlowLayoutPanel();

    if (edge.Edge == DockingEdge.Bottom || edge.Edge == DockingEdge.Top)
    {
        flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight;
        // Yes, add the scrollbar if needed.
        flowLayoutPanel.AutoScroll = true;
        flowLayoutPanel.WrapContents = true;
    }
    if (edge.Edge == DockingEdge.Right || edge.Edge == DockingEdge.Left)
    {
        flowLayoutPanel.FlowDirection = FlowDirection.TopDown;
        // Yes, add the scrollbar if needed.
        flowLayoutPanel.AutoScroll = true;
        flowLayoutPanel.WrapContents = false;
    }
}
@fdncred
Copy link
Author

fdncred commented Jul 17, 2019

Any ideas?

@fdncred
Copy link
Author

fdncred commented Jul 22, 2019

Peter @Wagnerp, Do you have time to help me figure this scenario out?

@Wagnerp
Copy link
Collaborator

Wagnerp commented Jul 22, 2019

Hi @fdncred

Is it possible to upload a test project, recreating this issue?

@fdncred
Copy link
Author

fdncred commented Jul 22, 2019

Thanks for responding @Wagnerp. I don't have an example I can share but perhaps we could use one of the Krypton Examples like "Standard Docking 2019".

In this example, if we focus on the "Input 5" page, it appears to be docked at the bottom.
image

When I drag it to the top right docking window like this...
image

I want to know how to tell that "Input 5" is now on DockingEdge.Right. That's really all my code in the original issue is asking. How can I get the DockingEdge after it's docked. I want to know this because I want to change the orientation of my flowlayout panel as demonstrated in my code above.

@Wagnerp
Copy link
Collaborator

Wagnerp commented Jul 22, 2019

Have you tried using the DockingEdge enumeration for a method which checks where the page is located?

@fdncred
Copy link
Author

fdncred commented Jul 22, 2019

@Wagnerp I'd love to. What method checks where the page is located?

@fdncred
Copy link
Author

fdncred commented Jul 22, 2019

I think I made a small discovery. The code above works sometimes when I dock on the edges. Sometimes it doesn't. Sometimes it works when I dock in the workspace. Sometimes it doesn't. I'm not sure what the magic is to detect where the page is docked exactly.

@Wagnerp
Copy link
Collaborator

Wagnerp commented Jul 23, 2019

I could probably insert a method into the library to do this. I'm not familiar with this part of the toolkit, so can you give me the name of the control that you're using?

@fdncred
Copy link
Author

fdncred commented Jul 23, 2019

I followed the example in the Standard Docking example located in Krypton-NET-5.470\Source\Krypton Docking Examples\Standard Docking. I create the Docking Pages nearly identical to this example.

private KryptonPage NewDocument()
{
    KryptonPage page = NewPage("Document ", 0, new ContentDocument());

    // Document pages cannot be docked or auto hidden
    page.ClearFlags(KryptonPageFlags.DockingAllowAutoHidden | KryptonPageFlags.DockingAllowDocked);
    
    return page;
}

private KryptonPage NewInput()          
{ 
    return NewPage("Input ", 1, new ContentInput(), null); 
}

private KryptonPage NewPropertyGrid()   
{ 
    return NewPage("Properties ", 2, new ContentPropertyGrid(), new Size(300, 300)); 
}

private KryptonPage NewPage(string name, int image, Control content, Size ?autoHiddenSizeHint = null)
{
    // Create new page with title and image
    KryptonPage p = new KryptonPage
    {
        Text = name + _count.ToString(),
        TextTitle = name + _count.ToString(),
        TextDescription = name + _count.ToString(),
        ImageSmall = imageListSmall.Images[image]
    };

    // Add the control for display inside the page
    content.Dock = DockStyle.Fill;
    p.Controls.Add(content);

    _count++;
    if (autoHiddenSizeHint.HasValue)
    {
        p.AutoHiddenSlideSize = autoHiddenSizeHint.Value;
    }
    return p;
}

private void Form1_Load(object sender, EventArgs e)
{
    // Setup docking functionality
    KryptonDockingWorkspace w = kryptonDockingManager.ManageWorkspace(kryptonDockableWorkspace);
    kryptonDockingManager.ManageControl(kryptonPanel, w);
    kryptonDockingManager.ManageFloating(this);

    // Add initial docking pages
    kryptonDockingManager.AddToWorkspace("Workspace", new KryptonPage[] { NewDocument(), NewDocument() });
    props3 = NewPropertyGrid();
    kryptonDockingManager.AddDockspace("Control", DockingEdge.Right, new KryptonPage[] { props3, NewInput() });
    kryptonDockingManager.AddDockspace("Control", DockingEdge.Bottom, new KryptonPage[] { NewInput(), NewPropertyGrid() });

    // Set correct initial ribbon palette buttons
    UpdatePaletteButtons();
}

The only thing different is I'm setting up an event so when a page is dropped it fires the code at the top of this issue.

        kryptonDockingManager.DoDragDropEnd += KryptonDockingManager_DoDragDropEnd;

If you're talking about some other control then I'm confused. By my way of thinking you could just modify the Standard Docking example to report where a page is dropped and that would probably suffice.

@Wagnerp
Copy link
Collaborator

Wagnerp commented Jul 23, 2019

KryptonPage is what I need. I will try to create a method that returns the DockingEdge for the chosen KryptonPage, is this what you mean?

@fdncred
Copy link
Author

fdncred commented Jul 23, 2019

Yes, that would be ideal but keep in mind that it appears that pages can be docked in a nested fashion. So it could be docked at the bottom of a page that is docked to the right of the form. I'm not sure how this would work exactly but what I'm really trying to learn is if the controls on the page should be drawn left to right or top to bottom.

If the page is docked to the bottom of another page and both are docked on the right, then the controls should be drawn top to bottom. If the control is docked to the bottom of a page that is docked to the bottom of the form then the controls should probably be drawn left to right.

Does that make sense?

BTW - I appreciate your help!

@Wagnerp
Copy link
Collaborator

Wagnerp commented Jul 23, 2019

What I'm thinking of is a method like this:

public DockingEdge LocatePage(KryptonPage page)
{
        return page.DockingEdge;
}

@fdncred
Copy link
Author

fdncred commented Jul 23, 2019

That's definitely a start and probably better than what I have now. Is there a way to get the hierarchy of nested pages so I could call that on all of my page's parents to understand where it's docked? Like if it's on the bottom but it's parent is docked at the right?

@Wagnerp
Copy link
Collaborator

Wagnerp commented Jul 23, 2019

There is something called KryptonPageCollection I don't know if that would help?

@fdncred
Copy link
Author

fdncred commented Jul 23, 2019

Sounds right. I'll do some research. Maybe I can foreach through that collection calling your method to figure out what i need.

@Wagnerp
Copy link
Collaborator

Wagnerp commented Jul 23, 2019

Do you know what property a KryptonPage uses to control the layout?

@fdncred
Copy link
Author

fdncred commented Jul 23, 2019

I'm afraid I do not. All I know is how the standard docking does it via the AddDockspace method on kryptonDockingManager. It just passes an edge. So, it may be a property of the docking manager versus the page. I'm not sure if the page knows where it's at. You can see in my code that nearly works that I'm querying the docking manager to figure things out.

var kPage = kryptonDockingManager.Pages.Where(x => x.Controls.ContainsKey("IndexingCtrl")).FirstOrDefault();
var edge = kryptonDockingManager.FindDockingEdgeDocked(kPage.UniqueName);

@fdncred
Copy link
Author

fdncred commented Jul 23, 2019

I figured out why my code sometimes works and sometimes doesn't. It only works when DockingLocation = Docked (aka dockLoc below). Otherwise, when DockingLocation = Workspace and it doesn't work because the edge property isn't set right - or something else is going on.

var dockLoc = kryptonDockingManager.FindPageLocation(kPage.UniqueName);

@fdncred
Copy link
Author

fdncred commented Aug 2, 2019

@Wagnerp Any luck?

@Wagnerp
Copy link
Collaborator

Wagnerp commented Aug 3, 2019

Hi @fdncred

I'm away at the moment, so I'm taking a short break from development. Will have a look when I get back.

@fdncred
Copy link
Author

fdncred commented Aug 20, 2019

Hey @Wagnerp
Had any time yet?

@Wagnerp
Copy link
Collaborator

Wagnerp commented Aug 20, 2019

Hi @fdncred

No, not yet, been really busy dividing up the toolkit into separate NuGet package modules. But I'm sure that there is a variable somewhere to control the location of the page.

@Wagnerp
Copy link
Collaborator

Wagnerp commented Aug 20, 2019

Hi @fdncred

It appears to use the DockingEdge enumeration:-

   // Add three horizontal-stacked pages to bottom edge of the panel
            kryptonDockingManager.AddDockspace("Control", 
                                               DockingEdge.Bottom, 
                                               new KryptonPage[] { NewDocument() }, 
                                               new KryptonPage[] { NewDocument() }, 
                                               new KryptonPage[] { NewDocument() });

@fdncred
Copy link
Author

fdncred commented Aug 22, 2019

Hey @Wagnerp
Of course it doesn't work, just trying to find the DockingEdge. I tried that before I even asked a question. You can see in my original question I tried that and it didn't work. Then I had a follow up with more details.

I figured out why my code sometimes works and sometimes doesn't. It only works when DockingLocation = Docked (aka dockLoc below). Otherwise, when DockingLocation = Workspace and it doesn't work because the edge property isn't set right - or something else is going on.

var dockLoc = kryptonDockingManager.FindPageLocation(kPage.UniqueName);

@Wagnerp
Copy link
Collaborator

Wagnerp commented Aug 22, 2019

Hi @fdncred

The example seems to use custom user controls that are placed on the workspace, if I recall the unique name returns a random string.

@fdncred
Copy link
Author

fdncred commented Aug 26, 2019

Hey @Wagnerp
I'm not sure what your point is? How will a random string help me to determine where a window is docked?

@Wagnerp
Copy link
Collaborator

Wagnerp commented Aug 27, 2019

Hi @fdncred

If you look at the example in the IDE, the designer does not show the pages. Instead everything is done via code. I don't think that the UniqueName will help you, what you need is the Name of the page.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants