By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,896 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,896 IT Pros & Developers. It's quick & easy.

Docking Form.UserControl

P: n/a
I have a User control that I load dynamically into a Form. The designer has
no property to let me dock it. How do i Dock it or get it to stretch out to
fill. Setting this.Dock = DockStyle.Fill; in the constructor did not work.
Neither did implementing the resize event.

thanks,
Hananiel
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
100
Hi Hananiel
Setting controls Dock property has to do the work.
The steps you should follow are:
1. Instantiate an objects of your control class.
MyControl ctrl = new MyControl();

2. Set all properties you need as well as the Dock property
ctrl.Dock = DockStyle.Fill;

3. Add the control as a child control to other contol or form

hostCtrl.SuspendLayout();
hostCtrl.Controls.Add(ctrl);
hostCtrl.ResumeLayout();

Suspend and resume layout methods pair don't have to be called if you add
only one control but they are very helpful when you add more then one.

Bare in mind that the control classes layout their children in backward
order that mans the las control added will be layouted first so if the host
control have already childern and you add the new control with filling dock
style that control will be layouted first and then the others. So, your
filling cotnrol will be either obscured by the others or will cover the
others. This is not what you want to achieve, I guess. So you have to make
sure that the filling control is always at index 0.
If you have already children of the host control you has to take one step
more when you add the control. You have to move it at index 0. Control
collection doesn't support Insert method and you should do it like this:

hostCtrl.SuspendLayout();
hostCtrl.Controls.Add(ctrl);
hostCtrl.Controls.SetChildIndex(ctrl, 0);
hostCtrl.ResumeLayout();

HTH
B\rgds
100

"Hananiel" <Ha******@junkmail.com> wrote in message
news:eH**************@TK2MSFTNGP12.phx.gbl...
I have a User control that I load dynamically into a Form. The designer has no property to let me dock it. How do i Dock it or get it to stretch out to fill. Setting this.Dock = DockStyle.Fill; in the constructor did not work.
Neither did implementing the resize event.

thanks,
Hananiel

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.