Export (0) Print
Expand All

How to: Use the Spring Property Interactively in a StatusStrip 

You can use the Spring property to position a ToolStripStatusLabel control in a StatusStrip control. The Spring property determines whether the ToolStripStatusLabel control automatically fills the available space on the StatusStrip control.

Example

The following code example demonstrates how to use the Spring property to position a ToolStripStatusLabel control in a StatusStrip control. The Click event handler performs an exclusive-or (XOR) operation to switch the value of the Spring property.

To use this code example, compile and run the application, and then click Middle (Spring) on the StatusStrip control to switch the value of the Spring property.

Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports System.Drawing
...' This code example demonstrates using the Spring property 
' to interactively center a ToolStripStatusLabel in a StatusStrip.
Class Form4
    Inherits Form

   ' Declare the ToolStripStatusLabel.
   Private middleLabel As ToolStripStatusLabel
   
   
   Public Sub New()
      ' Create a new StatusStrip control.
      Dim ss As New StatusStrip()
      
      ' Add the leftmost label.
      ss.Items.Add("Left")
      
      ' Handle middle label separately -- action will occur
      ' when the label is clicked.
      middleLabel = New ToolStripStatusLabel("Middle (Spring)")
      AddHandler middleLabel.Click, AddressOf middleLabel_Click
      ss.Items.Add(middleLabel)
      
      ' Add the rightmost label
      ss.Items.Add("Right")
      
      ' Add the StatusStrip control to the controls collection.
      Me.Controls.Add(ss)
    End Sub
   
   ' This event hadler is invoked when the 
   ' middleLabel control is clicked. It toggles
   ' the value of the Spring property.
    Sub middleLabel_Click(ByVal sender As Object, ByVal e As EventArgs)

        ' Toggle the value of the Spring property.
        middleLabel.Spring = middleLabel.Spring Xor True

        ' Set the Text property according to the
        ' value of the Spring property. 
        middleLabel.Text = IIf(middleLabel.Spring, _
        "Middle (Spring - True)", "Middle (Spring - False)")
    End Sub
End Class

Compiling the Code

See Also

Community Additions

ADD
Show:
© 2014 Microsoft