How can I make floating windows use their design size (and not the Dock Panel Suite's default size) with the Weifenluo Dock Panel suite?
Hint: I tried a proposition from the Dock Panel Suite forums at SF.net, but that doesn't se开发者_开发技巧em to work.
I stumbled across this question when looking for the answer myself, and found Timothy's answer to not work for me.
The problem was that the method he outlines also floated the window by default. (maybe that's a version difference)
I have solved this another way. I've created a base class that inherits from DockContent that all my document windows would inherit from. I then created another overload for the Show method that handles this (I used the DockPanelSuite source code to help build this method).
public void Show(DockPanel dockPanel, DockState dockState, Rectangle floatWindowBounds)
{
Show(dockPanel, dockState); //shows the panel like normal
//now for the part to initialize the float pane and size
if (DockHandler.FloatPane == null)
{
DockHandler.FloatPane = dockPanel.DockPaneFactory.CreateDockPane(this, DockState.Float, false);
DockHandler.FloatPane.FloatWindow.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
}
DockHandler.FloatPane.FloatWindow.Bounds = floatWindowBounds;
}
when CForm is derived from DockContent, I have a method within my MDIContainerWindow which looks like this
public void ShowForm(CForm pForm)
{
pForm.MdiParent = this;
Size lS = pForm.Size;
dockPanel.DefaultFloatWindowSize = lS;
pForm.Show(dockPanel);
pForm.VisibleState = DockState.Float;
}
This is working for me (in VB):
Dim MyForm As New MyForm
MyForm.Show(DockPanel, New Rectangle(MyForm.Location, MyForm.Size))
MyForm.DockState = DockState.DockRight
This worked for me:
var topLeft = dockPanel1.Location;
topLeft.X += (dockPanel1.Size.Width / 2 - newForm.Size.Width / 2);
topLeft.Y += (dockPanel1.Size.Height / 2 - newForm.Size.Height / 2);
newForm.Show(dockPanel1, new Rectangle(topLeft, newForm.Size));
精彩评论