473,472 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

UserControl.Size=Parent.ClientSize;

I want my custom UserControl to size and resize with its parent, a Form. But
when I use the code

Size=Parent.ClientSize;

in the constructor of myUserControl, Parent is null and the operation fails.
What is the proper place to put this code?
Jul 31 '06 #1
4 8874
Well, Size is a struct (value-type), so this wouldn't really do what you
want anyway...

Perhaps you should look more at docking and anchoring?

Marc
Jul 31 '06 #2
Hi,
Most probably it is done in the InitializeComponent method when you add the
control to the Controls collection

I also suggest you to use docking/anchoring.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Martijn Mulder" <i@mwrote in message
news:44***********************@news.wanadoo.nl...
>I want my custom UserControl to size and resize with its parent, a Form.
But when I use the code

Size=Parent.ClientSize;

in the constructor of myUserControl, Parent is null and the operation
fails. What is the proper place to put this code?

Jul 31 '06 #3
Thank you all,

docking/anchoring, it must be a lot like Java's LayoutManagers. What classes
and/or namespaces do I need to look into?
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
schreef in bericht news:%2****************@TK2MSFTNGP05.phx.gbl...
Hi,
Most probably it is done in the InitializeComponent method when you add
the control to the Controls collection

I also suggest you to use docking/anchoring.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Martijn Mulder" <i@mwrote in message
news:44***********************@news.wanadoo.nl...
>>I want my custom UserControl to size and resize with its parent, a Form.
But when I use the code

Size=Parent.ClientSize;

in the constructor of myUserControl, Parent is null and the operation
fails. What is the proper place to put this code?


Jul 31 '06 #4
They are properties on the control instance; e.g. to fill the available
space (which sounds like what you want):

control.Dock = DockStyle.Fill; // could be this.Dock in a ctor

If, however, you want to just maintain the distance from the edges (w/o
filling everything), then

control.Anchor = AnchorStyles.Top | AnchorStyles.Bottom| AnchorStyles.Left |
AnchorStyles.Right;

(or remove the edges you don't want to stick to; Top | Left is common, as is
Top | Left | Right)

Marc
Jul 31 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: balg | last post by:
An ActiveX control has a call to "UserControl.Parent" which fails when it is interopped and added to a .Net Form. Is there any way to access to .Net parent control/it's interfaces from VB6...
4
by: Chris | last post by:
I have a fairly straight-forward form that loads preferences upon running, and saves them upon exiting. Included in the preferences are things like window size & location, working directory, etc. ...
4
by: Ben Amada | last post by:
Hello, I have a user control which will be dynamically loaded from one of two parent ASPX webforms. Within the user control I'd like to be able to access a property from the parent webform. ...
37
by: Geoff Jones | last post by:
Hi Suppose I have two forms: Form1 and Form2. I create and show an instance of Form2 in the code of Form1 e.g. Dim myForm2 = New Form2 myForm2.Show() How do I tell myForm2 that Form1 is...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
1
by: Steve Kershaw | last post by:
I have this web page that has on it a user control. I have a need to access a method that resides in the parent web page from within this user control. It seems that there should be a way to do...
2
by: lotus | last post by:
HI All.. I'm realtively new to C#. I have MainForm which includes Parent usercontol, and this parent usercontrol also contains child usercontrol. MainForm --> Parent usercontrol --> child...
0
by: versatile | last post by:
Hi, I am using a vb 6.0 user control in my .net application. Usercontrol.Parent property of the user control is failing as it is getting the reference of the .net form. How can i make it work?
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...
0
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,...
0
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.