windows forms - how to get the size of an autosized control

B

BillE

I'm using VS2008, windows forms.

If I have a panel (for example) which has the Autosize property true, how
can I get its new size after it is populated with controls and resized?

The "size" property returns the initial size, even after it has resized to a
larger size.

Thanks
Bill
 
P

Pavel Minaev

I'm using VS2008, windows forms.

If I have a panel (for example) which has the Autosize property true, how
can I get its new size after it is populated with controls and resized?

The "size" property returns the initial size, even after it has resized to a
larger size.

Are you sure it had actually resized? For example, if it's
Visible==false at the moment, I don't see any reason for it to resize
immediately after you've added a few controls to it - it will probably
delay all layout logic at least until the control handle gets created.
If that's the case, try calling CreateHandle() on the panel, and see
if that helps.

If you can actually see the panel being resized, but Size still
returns the wrong value, than it is certainly a bug, and you should
file it at https://connect.microsoft.com/VisualStudio/Feedback
 

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