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
Contributors
User avatar
tvs praveen
Top Poster
Top Poster
Posts: 205
Joined: Tue Dec 08, 2009 6:20 am

VB 2008 Tutorial - About Text
tvs praveen
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;
Last edited by tvs praveen on Sat Jan 23, 2010 6:00 am, edited 1 time in total.
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

Re: VB 2008 Tutorial - About Text
Lewis
Nice exxplaining :D
Image
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Re: VB 2008 Tutorial - About Text
Nery
Its all clearly explained and well... You just made GDI+ easier to understand.
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: VB 2008 Tutorial - About Text
Usman55
I really liked it! Great Explanation!

Thanks!
Image
User avatar
tvs praveen
Top Poster
Top Poster
Posts: 205
Joined: Tue Dec 08, 2009 6:20 am

lewisfroom wrote:
Nice exxplaining :D
Thanks lewisfroom :D
User avatar
tvs praveen
Top Poster
Top Poster
Posts: 205
Joined: Tue Dec 08, 2009 6:20 am

Usman55 wrote:
I really liked it! Great Explanation!

Thanks!
Your welcome and thanks for reading this tutorial

I hope you like this tutorial! :D
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

Re: VB 2008 Tutorial - About Text
Lewis
Very intresting to read, to be honest :D
Image
7 posts Page 1 of 1
Return to “Tutorials”