다음을 통해 공유


방법: StatusStrip에서 대화형으로 Spring 속성 사용

업데이트: 2007년 11월

Spring 속성을 사용하여 StatusStrip 컨트롤에 있는 ToolStripStatusLabel 컨트롤의 위치를 지정할 수 있습니다. Spring 속성은 ToolStripStatusLabel 컨트롤이 StatusStrip 컨트롤에서 사용할 수 있는 공간을 자동으로 채우는지 여부를 확인합니다.

예제

다음 코드 예제에서는 Spring 속성을 사용하여 StatusStrip 컨트롤에서 ToolStripStatusLabel 컨트롤의 위치를 지정하는 방법을 보여 줍니다. Click 이벤트 처리기는 XOR(배타적 논리합) 연산을 수행하여 Spring 속성 값을 전환합니다.

이 코드 예제를 사용하려면 응용 프로그램을 컴파일하고 실행한 다음 StatusStrip 컨트롤에 있는 Middle (Spring)을 클릭하여 Spring 속성 값을 전환합니다.

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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;


...


// This code example demonstrates using the Spring property 
// to interactively center a ToolStripStatusLabel in a StatusStrip.
class Form4 : Form
{
    // Declare the ToolStripStatusLabel.
    ToolStripStatusLabel middleLabel;

    public Form4()
    {
        // Create a new StatusStrip control.
        StatusStrip ss = 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)");
        middleLabel.Click += new EventHandler(middleLabel_Click);
        ss.Items.Add(middleLabel);

        // Add the rightmost label
        ss.Items.Add("Right");

        // Add the StatusStrip control to the controls collection.
        this.Controls.Add(ss);
    }

    // This event hadler is invoked when the 
    // middleLabel control is clicked. It toggles
    // the value of the Spring property.
    void middleLabel_Click(object sender, EventArgs e)
    {
        // Toggle the value of the Spring property.
        middleLabel.Spring ^= true;

        // Set the Text property according to the
        // value of the Spring property. 
        middleLabel.Text = 
            middleLabel.Spring ? "Middle (Spring - True)" : "Middle (Spring - False)";
    }
}

코드 컴파일

이 예제에는 다음 사항이 필요합니다.

  • System.Design, System.Drawing 및 System.Windows.Forms 어셈블리에 대한 참조

Visual Basic 또는 Visual C#의 명령줄에서 이 예제를 빌드하는 방법에 대한 자세한 내용은 명령줄에서 빌드(Visual Basic) 또는 csc.exe를 사용한 명령줄 빌드를 참조하십시오. Visual Studio에서 코드를 새 프로젝트에 붙여넣어 이 예제를 빌드할 수도 있습니다.

참고 항목

참조

ToolStripStatusLabel

StatusStrip

ToolStrip

ToolStripItem

ToolStripMenuItem

기타 리소스

ToolStrip 컨트롤(Windows Forms)