how to set PreferredWidth of panel?

  • Thread starter Thread starter Sam Jost
  • Start date Start date
S

Sam Jost

can I somehow give a panel a PreferredWidth, so it act like a label in
a FlowLayoutPanel (trying to grow to the PreferredWidth if there is
enough room)?

Thanks,
Sam
 
I don't know of any attribute that will do what you want. There is
always the DockStyle.Fill but I am not sure if this will work for your
situation. It is also possible to just write your own resize function
to slowly increase or decrease the size of your control until it fills
the proper space. Wish I knew of something to make it easy, but I've
found more often than not I'm creating my own hacks with Windows Forms
b/c the tools just are not there. Good luck
 
Justin said:
I don't know of any attribute that will do what you want. There is
always the DockStyle.Fill but I am not sure if this will work for your
situation. It is also possible to just write your own resize function
to slowly increase or decrease the size of your control until it fills
the proper space. Wish I knew of something to make it easy, but I've
found more often than not I'm creating my own hacks with Windows Forms
b/c the tools just are not there. Good luck

DockStyle.Fill will make all items as large as the largest one.

Well, if no other way is possible I'll need to reverse-engineer how
label does it, since for label and linklabel it is working very well.

Sam (thinkin', maybe PreferredSize can be overloaded - checkin!)
 
Sam (thinkin', maybe PreferredSize can be overloaded - checkin!)

little digging turned up the virtual method GetPreferredSize, and
adding this small UserControl with autosize made the FlowLayoutPanel
use the full width:

public class MakeItBig : UserControl
{
public override Size GetPreferredSize(Size proposedSize)
{
return new Size(proposedSize.Width, 0);
}
}

Not the nicest solution I could imagine, but at least a solution at
all.

Sam
 
Back
Top