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.
}
}
}