Set the label's Spring property to True to get is to adjust its size automatically. To get ellipses you'll need to override the painting. Add a new class to your project and paste the code shown below. Compile. You'll get the new SpringLabel control in the status strip designer dropdown list.
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.StatusStrip)]
public class SpringLabel : ToolStripStatusLabel {
public SpringLabel() {
this.Spring = true;
}
protected override void OnPaint(PaintEventArgs e) {
var flags = TextFormatFlags.Left | TextFormatFlags.EndEllipsis;
var bounds = new Rectangle(0, 0, this.Bounds.Width, this.Bounds.Height);
TextRenderer.DrawText(e.Graphics, this.Text, this.Font, bounds, this.ForeColor, flags);
}
}
You'll need to do more work if you use the Image or TextAlign properties.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…