Power pack drawing primitives for VB.NET

Introduction

Microsoft has released version 2.0 of the Visual Basic 2005 Power Packs; the kit may be downloaded from here (http://msdn2.microsoft.com/en-us/vbasic/bb735936.aspx). Among other things, the kit contains a collection of drawing primitive controls in the form of an oval shape, a rectangle shape, and a line shape.

Power-pack-drawing-primitive1-in-VB.NET.gif

Figure 1: Using the Drawing Primitives from the Visual Basic 2005 Power Pack 2.0

Installed Controls

Upon installation of the tools; those items will appear in the toolbox under the heading of Visual Basic Power Packs v2.0. After the installation, you should see the Print Form, Line Shape, Oval Shape, and Rectangle Shape controls in the toolbox section. This article only addresses the drawing primitives.

Features.

Adding to a Form

In order to use a control, just drag the control from the toolbox and drop it onto the form as you would any other toolbox control; alternatively the controls may be added in code and added to the control collection.

Power-pack-drawing-primitive2-in-VB.NET.gif

Figure 2:  Power Packs Section of the Toolbox

Resize and Reposition

Once the drawing controls have been added to the page, the user may click on a control which in turn results in the display of the controls resizing handles. With the resizing handles present, the user may resize the oval or rectangle, or resize and reposition the beginning and end points of the line.

Power-pack-drawing-primitive3-in-VB.NET.gif

Figure 3:  Manipulating a Control at Design Time

Control Properties

Each controls properties are exposed in the IDE property grid upon selection of the control. The user may set fill colors and styles, border thicknesses, gradient effects, and other control related properties from this interface. Such properties may also be manipulated in code at run time.

Power-pack-drawing-primitive4-in-VB.NET.gif

Figure 3:  Setting Control Properties in the Property Grid

Control Events

The controls are configured to respond to a number of common events, by writing event handlers for these events is it possible to create responsive instances of the controls. In the example provided, the three oval controls are configured to show a roll-over effect when the mouse passes into and out of the control, and to respond to a click event.
The following code is used to alter the fill gradient color property of an oval control whenever the mouse enters the controls boundaries.

Private Sub OvalShape1_MouseEnter(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles OvalShape1.MouseEnter

OvalShape1.FillGradientColor = Color.CornflowerBlue

End Sub

 

And this code is used to restore the fill gradient color to its previous state once the mouse leaves the controls boundaries.

Private Sub OvalShape1_MouseLeave(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles OvalShape1.MouseLeave

OvalShape1.FillGradientColor = Color.FromArgb(255, 255, 192)

End Sub

Here, a click event handler is added for the same control and is used to manage the visible property on three line symbol controls also added to this page.

Private Sub OvalShape1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OvalShape1.Click

LineShape1.Visible = True

LineShape2.Visible = False

LineShape3.Visible = False

End Sub

Summary

Overall, the drawing primitives are a useful set of controls that may be used to enhance the appearance of an application GUI. The Microsoft site (http://msdn2.microsoft.com/en-us/vbasic/bb735936.aspx) is soliciting opinions and suggestions for additional controls and enhancements to the existing controls. Some additions that come to mind might be the inclusion of a transparent background label and a drop shadow enhancement to the existing controls (and the mentioned label control).


Similar Articles