Exforsys.com
 
Home Tutorials VB.NET 2005
 

Building Graphical Interface elements

 

Building Graphical Interface elements - Page 2

Page 2 of 3


Drawing Text on a Form


Drawing text on a Form can be achieved by the following method. You can use the System.Drawing.Graphics.Drawsting method of the System.Drawing.Graphics class to draw text. This example will be using the System.Windows.Forms.PaintEventArgs e, which is a parameter of System.Windows.Forms.PaintEventHandler. Let us see a demo for this task. In a new project add the following codes:


Click here for the Sample Code


You have to add a button and set the value for the text property to “Exit”.

The drawText method takes one parameter System.Windows.Forms.PaintEventArgs e. This method is called from the System.Windows.Forms.PaintEventHandler method which causes the Text to be drawn on the Form.

We declare a variable myText and assign it a value also. We also declare a fontFamily as an object of type FontFamily Which sets the name for the font family. We also declare a font object of the type Font and set values for its properties like FontFamily, Size, Style and Graphics Unit. This defines the visual properties of the Font that we want to display. The DrawString method which takes four parameters is used to draw Text. Here you can choose the type of brush by declaring your won brush. The out put is given below for the above project.



Drawing Shapes

We have seen how to create the Graphic object, draw a line and also to draw shapes. Now we shall see drawing other shapes. Drawing shapes and filling the shape with solid color or with gradient is accomplished by the various methods available in the Graphics Object. Let us walkthrough an example that demonstrates the power, flexibility of the language and also its richness. Create new Windows application in Visual Basic Express and add seven buttons to it. The window should look like the graphic given below:

The System.Drawing.Drawing2D namespace contains rich classes that support and extend the facilities for drawing. You can define you own pen with the following statement:

Dim MyPen As New Pen(MyColor, 5)

The pen that you have created will write in MyColor with thickness 5 pints. You can also define any type of brush from a range of brushes and assign a wide range of values that suit your needs. The methods of Graphics Object also support drawing with methods like, DrawLine, FillEllipse etc.

The GraphicsPath class has methods that help you to draw several shapes and texts at one time and this can be used to enhance the visual richness of the shapes and text. Applications use paths to draw outlines of shapes, fill the interiors of shapes, and create clipping regions. The graphics engine maintains the coordinates of geometric shapes in a path in world coordinate space.




A path may be composed of any number of figures (subpaths). Each figure is either composed of a sequence of connected lines and curves or a geometric shape primitive. The starting point of a figure is the first point in the sequence of connected lines and curves. The ending point is the last point in the sequence. The starting and ending points of a geometric shape primitive are defined by the primitive specification.

All these features have been used in the following demo:



Click here for the Sample Code


The output of the five options are given below:

Draw Line:



Draw Gradient Filled Ellipse:



Draw Polygon:



Draw Bezier:



Draw Text and Shapes with GraphicPath




Next Page: Building Graphical Interface elements - Page 3


Read Next: Visual Studio Adding Controls to Windows Form



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape