Click here to Skip to main content
13,549,847 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked
Posted 28 Feb 2010
Licenced CPOL

Control Resizing on a UserControl in WinForms

Rate this:
Please Sign up or sign in to vote.
Control resizing is a bit more mysterious than it might appear at first glance.
Let's say you have a UserControl, and on that user control, you have placed a control (any control), setting the Dock property to Fill. From hereon, we will refer to this control as the "filling control".

Let's further assume that you've placed a Panel (or other type of appropriate container) onto a Form, and set the Anchor property of the container to grow/shrink when you resize the form.

Finally, you would probably programatically add the user control (that contains the filling control) to the panel.

If you perform the steps outlined above, you will observe that the filling control will NOT resize itself to the container control, even though the container control will happily obey the Anchor property setting.

The problem is that the designer doesn't allow you to set either the Dock or the Anchor properties. You MUST manually set the appropriate property in the UserControl Load event handler (or someplace else equally appropriate).

I struggled with this for two hours (trying to capture Size events, and other things) before stumbling on the solution. I had completely missed the fact that there were no Dock/Anchor property settings in the designer for UserControl objects.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

John Simmons / outlaw programmer
Software Developer (Senior) Paddedwall Software
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.

My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
anon19319-May-13 16:54
memberanon19319-May-13 16:54 
GeneralReason for my vote of 1 Not a very clear example and respons... Pin
digger6927-Sep-10 6:15
memberdigger6927-Sep-10 6:15 
JokeDifficult to find out what you mean Pin
johannesnestler25-May-10 5:57
memberjohannesnestler25-May-10 5:57 
QuestionMissed something? Pin
PSU Steve2-Mar-10 3:01
memberPSU Steve2-Mar-10 3:01 
AnswerRe: Missed something? Pin
John Simmons / outlaw programmer3-Mar-10 3:43
memberJohn Simmons / outlaw programmer3-Mar-10 3:43 
GeneralRe: Missed something? Pin
PSU Steve3-Mar-10 4:25
memberPSU Steve3-Mar-10 4:25 
GeneralRe: Missed something? Pin
John Simmons / outlaw programmer3-Mar-10 11:50
memberJohn Simmons / outlaw programmer3-Mar-10 11:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03-2016 | 2.8.180515.1 | Last Updated 21 May 2010
Article Copyright 2010 by John Simmons / outlaw programmer
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid