调用DockPanel-Suite的"AutoHidden"以编程方式放置DockContent [英] Calling up DockPanel-Suite's "AutoHidden" DockContent programmatically

查看:296
本文介绍了调用DockPanel-Suite的"AutoHidden"以编程方式放置DockContent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法以编程方式显示自动隐藏"底座.

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

在网上找不到任何答案,尽管以下 SO问题建议.Show()应该已经完成​​了

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

我已经在最新的代码 NuGet版本中进行了尝试.

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

我的测试代码如下.

有人知道该怎么做吗?还是我做错了什么?

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

更新:显然,这是2.7.0中的错误,我打开了

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.

创建一个简单的Visual Studio Windows窗体应用程序,并使用以下代码替换主窗体的源文件内容:

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 SHOULD show the autohide-dock, but NOTHING happens.
            dc.Show();

我已将其替换为@roken的建议,现在可以使用了:

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.

        }
    }
}

推荐答案

要显示隐藏的自动隐藏内容,可以直接设置活动的自动内容:

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

dockPanel.ActiveAutoHideContent = dc;

对于我尚不清楚,是否无法通过Show()激活内容是一个已引入的错误.如果您有空的话,可以尝试针对版本 2.5.0 运行提供的代码,以查看如果Show()激活了您期望的内容?

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?

这篇关于调用DockPanel-Suite的"AutoHidden"以编程方式放置DockContent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆