Calling up DockPanel-Suite's “AutoHidden” DockContent programmatically

会有一股神秘感。 提交于 2019-12-13 14:22:21

问题


I am having trouble causing an 'autohide' dock to appear programmatically.

Couldn't find any answer around the net, though the following SO Question suggested that .Show() should have done the trick

I've tried this on the latest NuGet version of the code.

My test code is below.

Anyone know how to do it? or what I'm doing wrong?

Update: apparently this is a bug in 2.7.0, I've opened an issue for it with the project. @roken's answer is an excellent workaround, so I've updated the code below to reflect it.


My test Code

Create a simple Visual Studio Windows Form application, and replace the main form's source file content with this code:

using System;
using System.Windows.Forms;
using dps = WeifenLuo.WinFormsUI.Docking;

namespace testDockPanel
{
    public partial class Form1 : Form
    {
        private dps.DockPanel dockPanel;
        private dps.DockContent dc;
        private Control innerCtrl;

        public Form1()
        {
            InitializeComponent();

            dockPanel = new dps.DockPanel();
            dockPanel.Dock = DockStyle.Fill;
            dockPanel.DocumentStyle = dps.DocumentStyle.DockingWindow;

            toolStripContainer1.ContentPanel.Controls.Add(dockPanel);

            dc = new dps.DockContent();
            dc.DockPanel = dockPanel;
            dc.DockState = dps.DockState.DockRightAutoHide;
            innerCtrl = new WebBrowser() { Dock = DockStyle.Fill };
            dc.Controls.Add( innerCtrl );

This is the part of the code that didn't work:

            // This SHOULD show the autohide-dock, but NOTHING happens.
            dc.Show();

I've replaced it with @roken's suggestion and it now works:

            dockPanel.ActiveAutoHideContent = dc;
            innerCtrl.Focus(); // This is required otherwise it will autohide quickly.

        }
    }
}

回答1:


To show a hidden autohide content, you can set the active auto content directly:

dockPanel.ActiveAutoHideContent = dc;

It's not clear to me if the inability to activate the content via Show() is a bug that has been introduced. If you have a free moment could you try running the code you provided against version 2.5.0 to see if Show() activates the content like you expect?



来源:https://stackoverflow.com/questions/13843604/calling-up-dockpanel-suites-autohidden-dockcontent-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!