Link to home
Create AccountLog in
Avatar of John
JohnFlag for Canada

asked on

VB.NET ToolStripContainer / ToolStrip - How do I size / spring controls on the toolstrip

I'm using VB with Visual Studio 2010 to build a Windows Form application.

After playing for way too long with the ToolStrip control that I have placed on a ToolStripContainer, I have given up trying to figure out how to size the controls so they fill up the entire client area of the control. I was hoping someone could point out where I was going wrong.

In VB6, there was a spring property that made this a piece of cake.

I have a ToolStripLabel and a ToolStripProgressBar on the ToolStrip which sits on the bottom rafter (I hope that's the correct term) of a ToolStripContainer with its (the ToolStripContainer's) Dock set to full.

I can size the width of the ToolStripLabel  by entering it in the properties window (I couldn't figure out how to use the mouse to size it) but I'm stumped as to how to keep the progressbar a fixed width and have the label spring to the full width of the form as it's resized.

Any tips?
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

set the toolstrip's
Stretch

Open in new window

property to TRUE in the designer, or in code e.g
Me.ToolStrip1.Stretch = True

Open in new window

for ToolStrip1
Avatar of John

ASKER

Thanks.

Although the toolstrip is stretched across the top, the size of the label remains the same. Is there a way to have the controls within the toolstrip size themselves like spring used to do in a VB6 statusbar control?
The ToolStripStatusLabel does have a spring property, so it "should" be possible to inherit that property for other items on the toolstrip.

I'll investigate this option and give you some feedback.
Not much for now on that front, however, if you have only one item on the toolstrip  try this:

1. Set the AutoSize property of the item to False
2. Programatically set the width of the item to the parent toolstrip's width minus 5
e.g for ToolStripLabel1 residing in ToolStrip1
Me.ToolStripLabel1.Size = New Size(Me.ToolStrip1.Width - 5, 20)

Open in new window

Avatar of John

ASKER

Thanks but I have a progressbar as well.

Perhaps I should be using a statusbar instead.
ASKER CERTIFIED SOLUTION
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of John

ASKER

Thanks for your help. I was trying to see how much coding I could save in terms of form resizing and by using a ToolstropContainer I thought I could emulate a simple web browser with a toolstrip with textbox and button on top for the address bar, a webbrowser control in the container's client are and a toolstrip with label and progress bar on the bottom for the status bar.

I ended up doing it the old fashioned way and positioned and sized the controls myself in the form_resize event.