DockingControl
into the control would push that control right
up against the edges of the resize bar and grab area. Although there is nothing
wrong with this it didn't look very tidy, so instead I use this small helper class
that places a border around the provided control. The
DockingControl
creates an instance of this
BorderControl
passing in the user supplied
control. Then this
BorderControl
is used to fill the
DockingControl
rather than the user supplied one.
// Position the provided control inside a border to give a portrait picture effect class BorderControl : UserControl { // Instance variables private int _borderWidth = 3; private int _borderDoubleWidth = 6; private Control _userControl = null; public BorderControl(Control userControl) { _userControl = userControl; Controls.Add(_userControl); } // Must reposition the embedded control whenever we change size protected override void OnResize(EventArgs e) { // Can be called before instance constructor if (null != _userControl) { Size sizeClient = this.Size; // Move the user control to enforce the border area we want _userControl.Location = new Point(_borderWidth, _borderWidth); _userControl.Size = new Size(sizeClient.Width - _borderDoubleWidth, sizeClient.Height - _borderDoubleWidth); } // Ensure delegates are called base.OnResize(e); } }
Conclusion
This code was developed using a text editor and then calling the c# compiler on a command line. Therefore the look is modelled on the appearance of the VC6 environment (which I have) and not the newer look and feel of docking controls/windows from VC7 (which I don't have). I think it would be very easy to build on this code to allow floating controls and multiple docking controls in a docking bar. If you have any ideas or make any changes to the code then feel free to contact me as I would be very interested.
Comments