VB 2008 Tutorial - About Text
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
7 posts
Page 1 of 1
Text in GDI+ is easy to use and looks great. GDI+ takes advantage of text rendering options that provide clear and readable type with a number of layout options.
There are three main concepts that are important to understanding rudimentary typography for GDI+ and Windows Forms applications. These are the measurement systems involved, the way fonts are used and the way formatting works. Figure 1 shows some common typography terms in relation to various fonts.
Figure 1 [A typography primer]
![Image]()
Measurements
Font sizes are usually expressed in points. The font size is the height of the fonts bounding em square. Em is pronounced like the letter "M". Traditionally the uppercase M was the largest single character in in the typeface. This may not be the case anymore but the name has stuck. The Font object is the GDI+ container for a font which is created from a FontFamily that contains the description for the font.
Text layout is usually performed in points or at least some real-world layout method. It is important to remember that layouts in pixels are subject to unwanted variations because the pixel size on a screen is different to that of a printer. It's a good idea therefore to use a real-world measurement system. Because Points are all about printers measurements, these are the obvious choice for text layout coordinates. There's nothing to prevent you using other coordinates but you need to be aware of all the intricacies of the relationships between those systems and the size of the type.
Rendering fonts is an incredibly complex subject and it would be impossible to deal with it in detail in this article but in general, a font file is a complex description of a collection of glyphs that describe the characters in the font. Some characters use more than one glyph and it's even possible that the glyphs used for each character might change depending on the character that precedes of follows it. When you create a font by specifying the font family and size, the system creates descriptions of all the glyphs in the font that are adapted for the size and resolution of the output device. This is how a true-type font can maintain it's quality at 10 points or 1/7th of an inch in height and look good at 144 points or 2 inches high. Figure 2 illustrates this by showing the difference between 10 and 36 point type.
10 Point Verdana
18 Point Verdana
36 Point Verdana
Figure 2 [Normal text rendered image]
![Image]()
Figure 3 [Formatted text]
![Image]()
You can clearly see that the quality of the 10 point type is good even though the number of pixels used to display the type is low. When there are more pixels available the renderer uses a set of glyphs that have been constructed to take advantage of that extra resolution so the font quality is good at all sizes. This is because whenever you create a font object, the resolution, size and other details are taken into account to give the best possible result.
Using fonts
The first step is to create a Font object using the desired typeface. This can be accomplished in several ways but the simplest constructor for a font requires nothing more than a font-family name and a size.
Font fn=new Font("Times New Roman",10);
Dim fn As New Font("Times New Roman",10)
This creates a font with the default parameters and sets the size to 10 points in height. When a font is created you can use it to draw a string onto any Graphics object using the DrawString method. DrawString has several overloads that enable you to place text at a particular position or in a destination rectangle with various formatting options. The simplest option is to use the world coordinates and the currently selected page units to position the text. The following listing prints "Hello World!" on the form. Figure 3 shows the application at work.
Use this code to make text, You can control Text Font, Color and size to produce text using this code
Paste this code after Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object e As System.Windows.Forms.PaintEventArgs)
Handles MyBase.Paint
Dim fn As New Font("Hello World!", fn, Brushes.Black, 10, 10)
End Sub
*******************Thanks for reading my tutorial, I think this Tutorial will be most helpful to you!*******************
If you want any custom tutorial for you or you need any help in VS.NET, VB.NET, Software Coding, Designing and much more any help in Computer stuffs just ask me
Mostly i will help everyone in coding and design stuffs in on Computer
- Best regards hehaho;
- Tvs Praveen wahooo;
- Thanks CodeNStuff! for this amazing Website cooll;
There are three main concepts that are important to understanding rudimentary typography for GDI+ and Windows Forms applications. These are the measurement systems involved, the way fonts are used and the way formatting works. Figure 1 shows some common typography terms in relation to various fonts.
Figure 1 [A typography primer]

Measurements
Font sizes are usually expressed in points. The font size is the height of the fonts bounding em square. Em is pronounced like the letter "M". Traditionally the uppercase M was the largest single character in in the typeface. This may not be the case anymore but the name has stuck. The Font object is the GDI+ container for a font which is created from a FontFamily that contains the description for the font.
Text layout is usually performed in points or at least some real-world layout method. It is important to remember that layouts in pixels are subject to unwanted variations because the pixel size on a screen is different to that of a printer. It's a good idea therefore to use a real-world measurement system. Because Points are all about printers measurements, these are the obvious choice for text layout coordinates. There's nothing to prevent you using other coordinates but you need to be aware of all the intricacies of the relationships between those systems and the size of the type.
Rendering fonts is an incredibly complex subject and it would be impossible to deal with it in detail in this article but in general, a font file is a complex description of a collection of glyphs that describe the characters in the font. Some characters use more than one glyph and it's even possible that the glyphs used for each character might change depending on the character that precedes of follows it. When you create a font by specifying the font family and size, the system creates descriptions of all the glyphs in the font that are adapted for the size and resolution of the output device. This is how a true-type font can maintain it's quality at 10 points or 1/7th of an inch in height and look good at 144 points or 2 inches high. Figure 2 illustrates this by showing the difference between 10 and 36 point type.
10 Point Verdana
18 Point Verdana
36 Point Verdana
Figure 2 [Normal text rendered image]

Figure 3 [Formatted text]

You can clearly see that the quality of the 10 point type is good even though the number of pixels used to display the type is low. When there are more pixels available the renderer uses a set of glyphs that have been constructed to take advantage of that extra resolution so the font quality is good at all sizes. This is because whenever you create a font object, the resolution, size and other details are taken into account to give the best possible result.
Using fonts
The first step is to create a Font object using the desired typeface. This can be accomplished in several ways but the simplest constructor for a font requires nothing more than a font-family name and a size.
Font fn=new Font("Times New Roman",10);
Dim fn As New Font("Times New Roman",10)
This creates a font with the default parameters and sets the size to 10 points in height. When a font is created you can use it to draw a string onto any Graphics object using the DrawString method. DrawString has several overloads that enable you to place text at a particular position or in a destination rectangle with various formatting options. The simplest option is to use the world coordinates and the currently selected page units to position the text. The following listing prints "Hello World!" on the form. Figure 3 shows the application at work.
Use this code to make text, You can control Text Font, Color and size to produce text using this code
Paste this code after Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object e As System.Windows.Forms.PaintEventArgs)
Handles MyBase.Paint
Dim fn As New Font("Hello World!", fn, Brushes.Black, 10, 10)
End Sub
*******************Thanks for reading my tutorial, I think this Tutorial will be most helpful to you!*******************
If you want any custom tutorial for you or you need any help in VS.NET, VB.NET, Software Coding, Designing and much more any help in Computer stuffs just ask me
Mostly i will help everyone in coding and design stuffs in on Computer
- Best regards hehaho;
- Tvs Praveen wahooo;
- Thanks CodeNStuff! for this amazing Website cooll;
Last edited by tvs praveen on Sat Jan 23, 2010 6:00 am, edited 1 time in total.
Its all clearly explained and well... You just made GDI+ easier to understand.
Usman55 wrote:I really liked it! Great Explanation!Your welcome and thanks for reading this tutorial
Thanks!
I hope you like this tutorial!

7 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023