473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Docking Form.UserControl

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
1 9831
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David N | last post by:
Hi All, I just wonder if in C#, I can develop a user defined control that can call its parent function which is not yet developed. For example, how do I make my user control call a...
1
by: Jason | last post by:
Hi I would like a user control/form that can be either called as a dialog (ShowDialog) or embedded in another form (usercontrol). preferably, my dialog/usercontrol accepts an argument that...
4
by: Dennis Burdett | last post by:
I have a pretty complex control which use to be a C# windows form that I am trying to make into a control that can be dragged onto a VB6 form. I was able to make it into a com class that I could...
0
by: Geraldine Hobley | last post by:
Hello I have a problem changing the title of a crownwood docking form called CProjectInfo which is contained within anothe form called mdiClient 'definition in form mdiclien Public Shared...
2
by: Mark Collard | last post by:
The ToolBar control allows you to add toolbar buttons. When you add a button, the button is not only displayed in the toolbar, but also added as a separator control in the form/usercontrol your...
6
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use...
1
by: DK | last post by:
I have an image list control on a user control that I'm trying to access from the main form. I've tried different code but can't get it. I get an error: Cannot convert type...
5
by: Henrik | last post by:
Hello, I'm trying to make an event that will close a usercontrol and open another one. The first user control is for login and when the password have been validated, the event should fire and the...
5
by: Eitan Mizrahi | last post by:
I see a message on: http://bytes.com/topic/asp-net/answers/334831-winform-control-hosted-ie-fileio-security-exception-please-he I have got the same problem, which I cannot figure out what is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.