Status bar with Labels

lpaul

Active member
Joined
Dec 7, 2005
Messages
27
Programming Experience
Beginner
I have a status bar on a form and four labels above each panel. I need help with coding the labels to move (resize) with the statusbar panels. :confused:
 
Depending on how you control the Width of your StatusBarPanels, using the Labels' Anchor properties may not work. The StatusBarPanel class has a Width property. Whenever the Width of the StatusBarPanels may have changed, like on the Resize event of the StatusBar or when you change the Text property, you can resize and relocate your Labels based on the Width properties of the StatusBarPanels.
 
label sizing

Is there an example of how you would code you could share. I need the labels to move with the statuspanels when the panels move (spring) or grow. Thanks
 
lpaul said:
Is there an example of how you would code you could share. I need the labels to move with the statuspanels when the panels move (spring) or grow. Thanks
Just use the Width property of each StatusBarPanel to calculate the Left and Width properties of the Labels that corrspond to them.
 
status bar panels

I have four statusbarpanels in one status bar and four labels outside on top of the status bar itself that need to move when the panels grow or shrink --Thanks - hope this helps more. Some said to use calculations but I do not know where to start for that......



label1 label2 label 3 label 4
_________________________________________________________

panel 1 | panel2 | panel 3 | panel 4 |
_________________________________________________________
 
The code you write is just a reflection of the physical things you want to achieve. You want the Width of each Label to match the Width of the corresponding StatusBarPanel:
VB.NET:
Label1.Width = StatusBarPanel1.Width
Label2.Width = StatusBarPanel2.Width
and you want the Location of each Label to be based on the Right edge of the one to its left:
VB.NET:
Label1.Left = 0
Label2.Left = Label1.Right
You may need to tweak that a bit to allow for borders but a little trial and error should sort that out. I've already told you when you need to execute this code, so you would put it in its own procedure and call that any time it was needed.
 
Thanks - I was just thinking about that as I was searching also the internet - let me try that tomorrow and will let you know how it works. Thanks.
 
VB.NET:
[SIZE=2][COLOR=#0000ff] 
Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Resize([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Resize
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] xControl [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] StatusBarPanel
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] xControl [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].StatusBar1.Panels
xControl.Width = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].StatusBar1.Width / 4
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][/COLOR][/SIZE]

Regards ;)
 

Attachments

  • statusbarpanels.zip
    22.4 KB · Views: 32
Status Bar

I have added to the zip file you sent and it may explain more. When the check box is checked or unchecked it adds text to the label2 statusbarpanel2. (Text will be added to the other panels and will grow and shrink depening on the text). For each panel resize when text is changed - I need the label above that panel to stay in the center of the status bar panel. Thanks a bunch for you help. I think we are on the right track but I need a little more help.
 

Attachments

  • statusbarpanels.zip
    26.1 KB · Views: 33
I really don't understand what the problem is here. Why can't you just adapt the method that I suggested in post #9? Surely you can work out how to locate a Label in the middle of a StatusBarPanel. That's just a simple mathematics problem, not anything to do with programming at all.
 
He has a StatusBar at the bottom of the form with several StatusBarPanels. Above that, on the form surface (not in front of, as in z-order, but vertically above) he has the same number of Labels as StatusBarPanels. He wants each Label to relocate and/or resize to remain in the same position relative to the corresponding StatusBarPanel.
 
Back
Top