Preventing DockPanel from certain positions

7 posts, 0 answers
  1. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 05 Feb 2008 Link to this post

    Hi,

    I'm trying to prevent a dock panel beeing moved to top or buttom.

    My App looks explorer like - but the "navigation pane" can be docked to the right or to the left.

    I successfully handled to avoid "float" and other unwanted kinds of the panel.

    My next problem was a user dragging the panel arround.
    My first approach was to handel DockinStateChanging.
            private void rdmMain_DockingStateChanging(object sender, Telerik.WinControls.Docking.DockingChangingEventArgs e) {  
                if (e.DockableState != Telerik.WinControls.Docking.DockState.AutoHide && e.DockableState != Telerik.WinControls.Docking.DockState.Docked) {  
                    e.Cancel = true;  
                }  
                if (e.DockObject.DockPosition != DockPosition.Left && e.DockObject.DockPosition != DockPosition.Right) {  
                    e.Cancel = true;  
                }  
            }  
     
    BUT - I always get the previous DockPosition in this event!

    My next approach was to handle the already changed state.

            private void rdmMain_DockingStateChanging(object sender, Telerik.WinControls.Docking.DockingChangingEventArgs e) {  
                if (e.DockableState != Telerik.WinControls.Docking.DockState.AutoHide && e.DockableState != Telerik.WinControls.Docking.DockState.Docked) {  
                    e.Cancel = true;  
                }  
            }  
            private void rdmMain_DockingStateChanged(object sender, DockingChangedEventArgs e) {  
                if (e.DockObject.DockPosition != DockPosition.Left && e.DockObject.DockPosition != DockPosition.Right) {  
                    DockMenuTo(DockPosition.Left);  
                }  
            }  
     
     
    BUT - I still get the previous DockPosition in this event!
    This means I can't avoid that a user drags the panel to the top position,
    since the position shown in the DockingStateChanged handler is the PREVIOUS position!!

    So if dragged from left to top - it tells left!

    I guess this is some kind of a bug.

    Anyhow - is there a way to prevent Top / Bottom docking?
    Or at least prevent dragging?

    Regards

    Manfred
  2. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 05 Feb 2008 Link to this post

    Sorry for the prevoius post - I managed the things with the AllowXXX Properties.
    AllowDrag to false - works like a charm :)

    BUT - still the problem exists that the events deliver the wrong (old) dockposition.

    Since I could manage the things with "Allow" I ALMOST have no need for the "menu item preventer".
    Hide is disabled, Float is disabled, BUT still "TabbedDocument" is enabled.

    Maybe I'v overseen something - is there another "AllowXXX property" to disable this entry also?

    Or do I still have to handle the DockingStateChanging event to prevent the user selecting TabbeDocument?

    Regards

    Manfred 
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 06 Feb 2008 Link to this post

    Hi Manfred,

    Yes, for this scenario you should handle the DockingStateChanging event to prevent the user from selecting the TabbeDocument.

    We will include a new DockContextMenu property for the DockPanel and DocumentPane types in the upcoming service pack and you will be able to override the menu or cancel its showing. This enhancement will be available later this week.

     
    Kind regards,
    Julian Benkov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 11 Feb 2008 Link to this post

    Hi,

    I found the new property.
    It is not visible at designtime - but Intellisense shows it at runtime.

    The problem - when I try to set it it tells me that it is read only!!

    So not really a help I think.

    And the problem became worse.
    Before (pre SP1) AllowHinding set to false disabled hiding.
    BUT AutoHide was still possibel.
    Now this property disables AutoHide too...

    Maybe I'm doing something wrong - but can you tell me how to replace the default context menu with my own?

    I tried with "ContextMenuStrip" and this gives a strange result.
    First it shows the default CM.
    A secon right click brings up both menus - the default and above it my CMStrip.

    Regards

    Manfred 
  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 12 Feb 2008 Link to this post

    Hello Manfred,

    The DockContextMenu is readonly to provide safe processing of default context menus behavior. You can change items in the Items collection or disable its showing using the DropDownOpening event:

    dockPanel1.DockContextMenu.DropDownOpening += new CancelEventHandler(DockContextMenu_DropDownOpening); 

    Replace the default items with your own:

    void DockContextMenu_DropDownOpening(object sender, CancelEventArgs e)  
    {  
        dockPanel1.DockContextMenu.Items.Clear();  
     
        int index = dockPanel1.DockContextMenu.Items.Add(new DockMenuItem(DockState.Docked,"Test 1"));  
        dockPanel1.DockContextMenu.Items[index].Click += new EventHandler(menuItem_Click);  
    }  
     
    void menuItem_Click(object sender, EventArgs e)  
    {  
        DockMenuItem item = sender as DockMenuItem;  

    Disable the showing of the context menu:

    void DockContextMenu_DropDownOpening(object sender, CancelEventArgs e)  
    {  
        e.Cancel = true;  

    I hope this helps. If you have any other questions, please contact us again.

    Regards,
    Julian Benkov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 12 Feb 2008 Link to this post

    Hi,

    althoug the helptext promissed more (property DockContextMenu sounded like "set own menu") we could remove the unwanted items.

    This is good enough for a workaround.

    Our first approch (disable / enable) failed.
    It seems as if the enabled / disabled state is changed on runtime depending on the situation.

    Regards

    Manfred
  8. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 14 Feb 2008 Link to this post

    Hello Manfred,

    You can add all your logic to the DropDownOpening event and change the behavior depending on the current status and custom business logic of the current IDockable window.

    Here is a small asmple illustrating this approach:

    void DockContextMenu_DropDownOpening(object sender, CancelEventArgs e)  
    {  
        DockContextMenu item = sender as DockContextMenu;  
          
        if (item != null)  
        {  
            if(item.DockWindow == dockPanel2)  
            {  
                e.Cancel = true;  
            }  
     
            if (item.DockWindow == documentPane1)  
            {  
                documentPane1.DockContextMenu.Items.Clear();  
                documentPane1.DockContextMenu.Items.Add(new RadMenuItem("Test Menu"));  
            }  
        }  

    I hope this helps. If you have any additional questions, please contact us.

    All the best,
    Julian Benkov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for WinForms is Visual Studio 2017 Ready