Technical Training
VB.NET 2005Table of Contents
Building Graphical Interface elements
Building Graphical Interface elements - Page 2
Building Graphical Interface elements - Page 3Building Graphical Interface elements Page - 2
Building Graphical Interface elements
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
VB.NET 2005
- VB.NET 2005 Free Training
- The .NET Framework Architecture Part 1
- The .NET Framework Architecture Part 2
- Application Class and Message Class
- Implementing Class Library Object
- Visual Studio.NET Namespaces
- .NET Assemblies
- Differences between VB.NET 1.0 and VB.NET 2.0
- Introducing VB.NET Windows Forms
- Visual Studio Windows Forms Designer
- Exploring the Forms Designer generated code
- Setting and Adding Properties to Windows Form
- Implementing Inheritance
- Event Handling In Visual Basic .NET
- Building Graphical Interface elements
- .NET Common Windows Forms Controls Part 1
- .NET Common Windows Forms Controls Part 2
- Common Controls and Handling Control Events
- DomainUpDown and NumericUpDown Controls
- Dialog Boxes in Visual Basic .NET
- Visual Studio Adding Controls to Windows Form
- VB.NET Validation Controls
- Working with Menu Controls
- VB.NET MDI Applications
- .NET Exceptions
- VB.NET Creating and Managing Components Part 1
- VB.NET Creating and Managing Components Part 2
- Simple Data Binding
- .NET Complex Data Binding
- .NET Data Form Wizard
- Data Manipulation with ADO.NET
- SQL Server Stored Procedures
- SQL Server Ad Hoc Queries
- Finding and Sorting Data in DataSets
- ADO.NET Object Model
- Working with DataSets
- Using XML Data
- Working with File System in .NET
- Creating Web Service
- Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
- Web Reference and Web Services
- Web Services - SOAP, WSDL, Disco and UDDI
- Web Application Testing in VB.NET 2005
- Web Application Tracing and Debugging
- Working with Legacy Code and COM Components
- ActiveX Controls and Legacy Code
- Windows Application Testing
- VB.NET Windows Application Testing
- Tracing VB.NET Windows Application
- Debugging Windows Applications In Visual Studio.NET 2005
- Deploying Windows Applications In Visual Studio.NET 2005
- Customizing Setup Project in Visual Studio.NET 2005
- Shared Assembly
- Microsoft .NET Creating Installation Components
- The Registry Editor in Visual Studio.NET 2005
- The File Types Editor







