The following code example is designed for use with Windows Forms, and it requires http://msdn.microsoft.com/en-us/library/system.windows.forms.painteventargs.aspxe, which is a parameter of the http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint.aspx event handler. The code performs the following actions:
· Creates a text string to draw.
· Defines the font as Arial (16pt).
· Creates a solid, black brush to draw with.
· Creates the coordinates of a point for the upper-left corner at which to draw the text.
· Sets the format of the string to draw vertically
· Draws the string to the screen using the font, brush, destination point, and format.
VB.NET Example:-
Public Sub DrawStringFloatFormat(ByVal e As PaintEventArgs)
' Create string to draw.
Dim drawString As [String] = "Sample Text"
' Create font and brush.
Dim drawFont As New Font("Arial", 16)
Dim drawBrush As New SolidBrush(Color.Black)
' Create point for upper-left corner of drawing.
Dim x As Single = 150.0F
Dim y As Single = 50.0F
' Set format of string.
Dim drawFormat As New StringFormat
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical
' Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, _
x, y, drawFormat)
End Sub
C#.NET Example:-
public void DrawStringFloatFormat(PaintEventArgs e)
{
// Create string to draw.
String drawString = "Sample Text";
// Create font and brush.
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
// Create point for upper-left corner of drawing.
float x = 150.0F;
float y = 50.0F;
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
}
link to refer: http://msdn.microsoft.com/en-us/library/d3thd43b.aspx