Прочитај на енглеском Уреди

Делите путем


StringFormat Constructors

Definition

Initializes a new StringFormat object.

Overloads

StringFormat()

Initializes a new StringFormat object.

StringFormat(StringFormat)

Initializes a new StringFormat object from the specified existing StringFormat object.

StringFormat(StringFormatFlags)

Initializes a new StringFormat object with the specified StringFormatFlags enumeration.

StringFormat(StringFormatFlags, Int32)

Initializes a new StringFormat object with the specified StringFormatFlags enumeration and language.

StringFormat()

Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs

Initializes a new StringFormat object.

C#
public StringFormat();

Remarks

The following table shows initial property values for an instance of StringFormat class.

Property Initial Value
FormatFlags 0 (no flags are set)
HotkeyPrefix None

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.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

StringFormat(StringFormat)

Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs

Initializes a new StringFormat object from the specified existing StringFormat object.

C#
public StringFormat(System.Drawing.StringFormat format);

Parameters

format
StringFormat

The StringFormat object from which to initialize the new StringFormat object.

Exceptions

format is null.

Examples

The following code example demonstrates the following members:

This example is designed to be used with Windows Forms. Paste the code into a form and call the ShowLineAndAlignment method when handling the form's Paint event, passing e as PaintEventArgs.

C#
private void ShowLineAndAlignment(PaintEventArgs e)
{

    // Construct a new Rectangle .
    Rectangle  displayRectangle = 
        new Rectangle (new Point(40, 40), new Size (80, 80));

    // Construct 2 new StringFormat objects
    StringFormat format1 = new StringFormat(StringFormatFlags.NoClip);
    StringFormat format2 = new StringFormat(format1);

    // Set the LineAlignment and Alignment properties for
    // both StringFormat objects to different values.
    format1.LineAlignment = StringAlignment.Near;
    format1.Alignment = StringAlignment.Center;
    format2.LineAlignment = StringAlignment.Center;
    format2.Alignment = StringAlignment.Far;

    // Draw the bounding rectangle and a string for each
    // StringFormat object.
    e.Graphics.DrawRectangle(Pens.Black, displayRectangle);
    e.Graphics.DrawString("Showing Format1", this.Font, 
        Brushes.Red, (RectangleF)displayRectangle, format1);
    e.Graphics.DrawString("Showing Format2", this.Font, 
        Brushes.Red, (RectangleF)displayRectangle, format2);
}

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.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

StringFormat(StringFormatFlags)

Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs

Initializes a new StringFormat object with the specified StringFormatFlags enumeration.

C#
public StringFormat(System.Drawing.StringFormatFlags options);

Parameters

options
StringFormatFlags

The StringFormatFlags enumeration for the new StringFormat object.

Examples

The following code example demonstrates the following members:

This example is designed to be used with Windows Forms. Paste the code into a form and call the ShowLineAndAlignment method when handling the form's Paint event, passing e as PaintEventArgs.

C#
private void ShowLineAndAlignment(PaintEventArgs e)
{

    // Construct a new Rectangle .
    Rectangle  displayRectangle = 
        new Rectangle (new Point(40, 40), new Size (80, 80));

    // Construct 2 new StringFormat objects
    StringFormat format1 = new StringFormat(StringFormatFlags.NoClip);
    StringFormat format2 = new StringFormat(format1);

    // Set the LineAlignment and Alignment properties for
    // both StringFormat objects to different values.
    format1.LineAlignment = StringAlignment.Near;
    format1.Alignment = StringAlignment.Center;
    format2.LineAlignment = StringAlignment.Center;
    format2.Alignment = StringAlignment.Far;

    // Draw the bounding rectangle and a string for each
    // StringFormat object.
    e.Graphics.DrawRectangle(Pens.Black, displayRectangle);
    e.Graphics.DrawString("Showing Format1", this.Font, 
        Brushes.Red, (RectangleF)displayRectangle, format1);
    e.Graphics.DrawString("Showing Format2", this.Font, 
        Brushes.Red, (RectangleF)displayRectangle, format2);
}

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.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

StringFormat(StringFormatFlags, Int32)

Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs
Source:
StringFormat.cs

Initializes a new StringFormat object with the specified StringFormatFlags enumeration and language.

C#
public StringFormat(System.Drawing.StringFormatFlags options, int language);

Parameters

options
StringFormatFlags

The StringFormatFlags enumeration for the new StringFormat object.

language
Int32

A value that indicates the language of the text.

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.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