Training
Module
Format alphanumeric data for presentation in C# - Training
Explore basic methods in C# to format alphanumeric data.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
When you perform custom drawing, you can draw text in a single horizontal line starting at a specified point. You can draw text in this manner by using the DrawString overloaded method of the Graphics class that takes a Point or PointF parameter. The DrawString method also requires a Brush and Font
You can also use the DrawText overloaded method of the TextRenderer that takes a Point. DrawText also requires a Color and a Font.
The following illustration shows the output of text drawn at a specified point when you use the DrawString overloaded method.
Use the DrawString method, passing the text you want, Point or PointF, Font, and Brush.
using (Font font1 = new Font("Times New Roman", 24, FontStyle.Bold, GraphicsUnit.Pixel)){
PointF pointF1 = new PointF(30, 10);
e.Graphics.DrawString("Hello", font1, Brushes.Blue, pointF1);
}
Dim font1 As New Font("Times New Roman", 24, FontStyle.Bold, GraphicsUnit.Pixel)
Try
Dim pointF1 As New PointF(30, 10)
e.Graphics.DrawString("Hello", font1, Brushes.Blue, pointF1)
Finally
font1.Dispose()
End Try
Use the DrawText method, passing the text you want, Point, Font, and Color.
using (Font font = new Font("Times New Roman", 24, FontStyle.Bold, GraphicsUnit.Pixel))
{
Point point1 = new Point(30, 10);
TextRenderer.DrawText(e.Graphics, "Hello", font, point1, Color.Blue);
}
Dim font As New Font("Times New Roman", 24, FontStyle.Bold, GraphicsUnit.Pixel)
Try
Dim point1 As New Point(30, 10)
TextRenderer.DrawText(e.Graphics, "Hello", font, point1, Color.Blue)
Finally
font.Dispose()
End Try
The previous examples require:
e
, which is a parameter of PaintEventHandler..NET Desktop feedback feedback
.NET Desktop feedback is an open source project. Select a link to provide feedback:
Training
Module
Format alphanumeric data for presentation in C# - Training
Explore basic methods in C# to format alphanumeric data.