views:

41

answers:

3

I am using this nice code which by the way if you are aware of any better way to accomplish this, I really appreciate letting us know . so here is the Toolbar that can float :

http://en.csharp-online.net/Tool,_Menu,_and_Status_Strips%E2%80%94Floating_ToolStrips

good, but what if I only have 4 buttons on this toolbar, when I make it float it is still the same size as it was docked to the form before but I wish it could resize itself and just be as long as it needs to be to show its buttons on it .

+1  A: 

You can add up the widths of the individual toolstrip items and use that as the width of your form.

Replace this:

floatForm.ClientSize = this.Size;

with this:

//Adjust min value for your needs. It should account for the width of the
//toolstrip, borders, etc.
int minWidth = 20;  

int newWidth = minWidth;
foreach (ToolStripItem item in this.Items)
{
    newWidth += item.Size.Width;
}
floatForm.ClientSize = new Size(newWidth, this.Size.Height);
msergeant
+1  A: 
  m_floatForm.AutoSize = True
  m_floatForm.AutoSizeMode = AutoSizeMode.GrowAndShrink
serhio
A: 

esta interesante

Silomid