StringFormat.Trimming Property

Definition

Gets or sets the StringTrimming enumeration for this StringFormat object.

C#
public System.Drawing.StringTrimming Trimming { get; set; }

Property Value

A StringTrimming enumeration that indicates how text drawn with this StringFormat object is trimmed when it exceeds the edges of the layout rectangle.

Examples

The following example shows how to set the Trimming property and how to use the StringTrimming enumeration. This example is designed to be used with a Windows Form. Paste this code into a form and call the ShowStringTrimming method when handling the form's Paint event, passing e as PaintEventArgs.

C#
private void ShowStringTrimming(PaintEventArgs e)
{

    StringFormat format1 = new StringFormat();
    string quote = "Not everything that can be counted counts," +
        " and not everything that counts can be counted.";
    format1.Trimming = StringTrimming.EllipsisWord;
    e.Graphics.DrawString(quote, this.Font, Brushes.Black, 
        new RectangleF(10.0F, 10.0F, 90.0F, 50.0F), format1);
}

Applies to

Produkt Verzie
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10