StringFormat originalFormat = new StringFormat(); originalFormat.Alignment = StringAlignment.Center; StringFormat newFormat = (StringFormat)originalFormat.Clone(); newFormat.Alignment = StringAlignment.Far;
StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; using (Font font = new Font("Arial", 12)) { graphics.DrawString("Hello, world!", font, Brushes.Black, new Rectangle(0, 0, 100, 50), format); }This example uses a StringFormat instance to center the text drawn on a GDI+ graphics object. While we do not clone the StringFormat instance in this example, we could clone it and modify its properties to create a new formatting option. Package library: This method is part of the System.Drawing package in the .NET Framework and .NET Core.