Docking Control

Shrink the User Control

When developing this code I noticed that placing the user supplied control for the 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.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++: an octopus made by nailing extra legs onto a dog.” - Steve Taylor