问题
I have just downloaded the WeifenLuo(Dock Panel Suite) and trying to work with that but I couldn't find a specific documentation on how to use it.
And I have gone through some of the SO questions and finally got something to get started.
Here is what I have done: I have created a ToolboxWindow class like shown below:
Public Class ToolboxWindow
Inherits WeifenLuo.WinFormsUI.Docking.DockContent
Public Sub New()
End Sub
End Class
And trying to create an instance of this toolbox in this way:
Public Class Form1
Private toolboxWindow As ToolboxWindow
Public Sub New()
Me.InitializeComponent()
'Create new ToolboxWindow
toolboxWindow = New ToolboxWindow()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
'Show it
toolboxWindow.Show(DockPanel1, DockState.DockLeft)
End Sub
End Class
And the final result it shows me this way?
1.How to adjust
the size
of the toolbox
.
2.If I have form2
with the dock panel
how do I show in the form1
Thanks in Advance!
回答1:
Q1 How to adjust the size of the toolbox.
The DockPanel container has a DockLeftPortion
property (Right, Bottom and Top too). This specifies the width of the left area as either pixels or a proportion of the available area.
I haven't seen anything that allows it to take on the size of the docked controls.
Q2 If I have form2 with the dock panel how do I show in the form1
If you have two top level application forms each with a dock panel, you pass the appropriate dockpanel control as the first parameter to the Show()
method.
Is this what you meant by Q2?
回答2:
This is an old post, but whilst looking for something else, I see that I have, just today, found the answer.
How To Resize DockForms
To resize the forms, here is a way that will let you modify them. Look here. Just paste this into the namespace of your main sub (I put mine at the bottom):
public class CustomFloatWindow : FloatWindow {
public CustomFloatWindow(DockPanel dockPanel, DockPane pane)
: base(dockPanel, pane) {
FormBorderStyle = FormBorderStyle.Sizable;
MaximizeBox = false;
MinimizeBox = false;
Width = 50;
}
public CustomFloatWindow(DockPanel dockPanel, DockPane pane, Rectangle bounds)
: base(dockPanel, pane, bounds) {
FormBorderStyle = FormBorderStyle.Sizable;
MaximizeBox = false;
MinimizeBox = false;
Width = 50;
}
}
public class CustomFloatWindowFactory : DockPanelExtender.IFloatWindowFactory {
public FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane, Rectangle bounds) {
return new CustomFloatWindow(dockPanel, pane, bounds);
}
public FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane) {
return new CustomFloatWindow(dockPanel, pane);
}
}
And then, to make it work, paste this into the main form:
dockPanel.Extender.FloatWindowFactory = new CustomFloatWindowFactory();
How To Show the Docked Panel
To show the panel docked in the dock-form, you have to create a sort of form-template, and in its code, where it says Form
, change it to DockContent
, like this:
Now, in a form which you want to use in the docking panel, modify the code to look like this (notice the DockContent
as the type, rather than Form
):
namespace mynamespace{
public partial class MyForm: DockContent {
public dockform_MyForm() {
InitializeComponent();
}
private void MyForm_Load(object sender, EventArgs e) {
}
}
}
Then, to dock it, we first declare the new form, then create it. I like this:
//in your form main sub:
private dockform_MyForm dform_MyForm = new MyForm();
//now, somewhere in your form's class, put this:
public void showMyFormDocked() {
dform_MyForm = new MyForm();
dform_MyForm.Show(dockPanel);
}
Finally, to show the form, you just call this from anywhere:
showMyFormDocked();
I learned all this from studying the source docs and trying to reproduce them.
来源:https://stackoverflow.com/questions/8674266/using-weifenluo-dockpanel-suite