Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Du kan använda egenskapen Spring för att placera en ToolStripStatusLabel kontroll i en StatusStrip kontroll. Egenskapen Spring avgör om ToolStripStatusLabel-kontrollen automatiskt fyller det tillgängliga utrymmet på StatusStrip-kontrollen.
Exempel
Följande kodexempel visar hur du använder egenskapen Spring för att placera en ToolStripStatusLabel kontroll i en StatusStrip kontroll. Händelsehanteraren Click utför en exklusiv åtgärd eller (XOR) för att växla värdet för egenskapen Spring.
Om du vill använda det här kodexemplet kompilerar och kör du programmet och klickar sedan på Mitten (Spring) på kontrollen StatusStrip för att växla värdet för egenskapen Spring.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
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 : 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)";
}
}
' 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
Kompilera koden
Det här exemplet kräver:
- Referenser till sammansättningarna System.Design, System.Drawing och System.Windows.Forms.
Se även
.NET Desktop feedback