473,569 Members | 2,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Docking Form.UserContro l

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 9852
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.Suspen dLayout();
hostCtrl.Contro ls.Add(ctrl);
hostCtrl.Resume Layout();

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.Suspen dLayout();
hostCtrl.Contro ls.Add(ctrl);
hostCtrl.Contro ls.SetChildInde x(ctrl, 0);
hostCtrl.Resume Layout();

HTH
B\rgds
100

"Hananiel" <Ha******@junkm ail.com> wrote in message
news:eH******** ******@TK2MSFTN GP12.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
11866
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 to-be-developed-function cmdOkay_Click() function as described below. 1. Create an user control that contains an OK button as below Public Class...
1
1292
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 specifies which mode it should be, i.e. embedded or dialog... what is the best way of accomplishing this?
4
9287
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 then go to VB6 and add the reference and call the object there without any problems. When I try to make it into a UserControl, I get it to build...
0
1009
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 CProjectInfo As Conten Setting the title in another form strTitle = "Project Info - Current Project - " & StrHeader & " Current Job - " & CurrJobKe...
2
2817
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 toolbar exists in. I'm writing my own usercontrol which contains various different controls (e.g. Panel, Button). I would like these controls to be...
6
12125
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 binding like normal. The problem I am running into is that my UserControl ends up with a different BindingContext then the ParentForm it is...
1
3710
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 'System.Windows.Forms.Control' to 'System.Windows.Forms.ImageList' ImageList il = new ImageList(); il = (ImageList)userControlMedia1.Controls.Find("imageListMedia",...
5
2074
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 event/form would close the usercontrol. The problem is that the form can't see the event with the error "are you missing a using directive or an...
5
2500
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 solution for weeks. I have Windows 7 (Home premium edition), framework 3.5 (how can I check that, if gacutil is correct version, if it metters,...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7681
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.