C#: Centering a ToolStripLabel
Comments available as RSS 2.0
If you have a toolstrip for navigation, you might want to have buttons on the left and the right, and a label in the centre. There’s no way to stretch the label automatically, but this snippet will resize the label to fill the rest of the ToolStrip. The only requirement is that all of the buttons are the same width.
private void CenteredLabel_Resize() { int remainingWidth = 144 + btnPrevSkip.Bounds.Left + 2; lblCenteredLabel.Width = toolStrip1.ClientSize.Width - remainingWidth; }
You need to replace 144 with the total width of all of the other items on the ToolStrip.







Comments
Leave a Comment