Compound Custom Control - How to Trap Resize in Design Mode

S

Stewart Berman

I have a compound custom control derived from UserControl. It has three controls on it -- two
custom controls and a Label control. When the control is added to a from and then resized using the
Designer how do I trap the resize event so I can resize the child controls?

I have tried the using:
protected override void OnSizeChanged(EventArgs e)

But it doesn't get called when the control is resized in the Designer.
 
S

Stewart Berman

I am just getting back into this after a long stretch in the Access/Excel world. Since I started
programming Windows Apps in C and a little assembler (before C++ was thought of much less available)
my initial response to any special need is to roll my own. I appreciate the note and have to
remember to see what's available before reinventing the wheel.

OTOH, it is interesting to see what can be done at the lower levels.
 
Z

Zhi-Xin Ye [MSFT]

Hello Stewart ,

Thank you for using Microsoft Managed Newsgroup Service, I'm Zhi-Xin Ye,
it's my pleasure to work with you on this issue.

You can override the the OnSizeChanged method to adjust the size for the
child controls, however, the formal way to resize/relocation the child
controls is to set the Anchor property or Dock property, then the child
controls would automatically adjust their size/location when the parent
container resizes.

For more information, you can refer to these document:

Control.Anchor Property
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor.
aspx

Control.Dock Property
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.as
px

If you have any questions or concerns, please feel free to let me know.

Have a great day!

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Stewart Berman

child controls, however, the formal way to resize/relocation the child
controls is to set the Anchor property or Dock property, then the child
controls would automatically adjust their size/location when the parent
container resizes.

There are three controls on top of the custom control. The middle one has to be centered and
maintain its height. The top and bottom controls need to fill the two spaces -- one between the top
of the middle control and the top of the custom control container and the other between the bottom
of the middle control and the bottom of the custom control container. IOW:
---------------------------------
| |
| Top control | Fills the top of the custom control
| |
|-------------------------------|
| |
| Middle control | Centered -- Height doesn't change
| |
|-------------------------------|
| |
| Bottom control | Fills the bottom of the custom control|
| |
|-------------------------------|
 
Z

Zhi-Xin Ye [MSFT]

Hi Stewart,

You can set Dock property of the control at the top to Dock.Top, set Dock
property of the control at middle to Dock.Fill and set Dock property of the
control at bottom to Dock.Bottom.

If you have any questions or concerns, please feel free to let me know.

Have a great day!

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Stewart Berman

That will keep the height of the top and bottom controls and grow/shrink the middle one. I want to
keep the middle one constant and grow/shrink the top and bottom controls.
 
Z

Zhi-Xin Ye [MSFT]

Hi Stewart,

You can use a TableLayoutPanel control to host the controls. Steps for your
information:

1. Create a UserControl;
2. Drag a TableLayoutPanel control from the toolbox to the UserControl;
3. Click the smart tag on the right-top corner of the TableLayoutPanel
control;
4. Click the "Remove Last Column" link to remove the extra column, here we
need only one column;
5. Click the "Add Row" link to add a new row into the TableLayoutPanel, we
need three rows here;
6. Drag the three custom controls into each row accordingly;
7. Set the Dock property for the custom controls to Dock.Fill;
8. Click the "Edit Rows and Columns" link on the smart tag;
9. On the "Column and Row Styles" dialog, select "Rows" from the "Show"
list;
10. Set up styles for the rows as follows:

Row1 Percent 50.00%
Row2 Absolute 80 (You can specify other value based on your
requirement)
Row3 Percent 50.00%

11. Click "OK" to finish the editing;
12. Set the Dock property for the TableLayoutPanel to Dock.Fill;
13. Build the program;

Now, when you resize the UserControl, you'll find that the control in the
middle is in fix size, the top and bottom ones are resized.

Please try my suggestion and let me know whether it make sense to you.

Have a happy day!

Best Regards,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel

free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Z

Zhi-Xin Ye [MSFT]

Hi Stewart,

Does my last reply make sense to you? If you need further help, please feel
free to let me know, I will be happy to be of assistance.

Have a nice day!


Best Regards,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Stewart Berman

It worked -- with a bit of effort. Exposing some of the properties of the top layer controls
through the user control was a bit more effort but it did eliminate the need to handle the resize
event.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top