Visual Basic Code of the Week (COTW)
http://www.codeoftheweek.com
Issue #94
Online Version at http://www.codeoftheweek.com/membersonly/bi/0094.html (paid subscribers only)
All content and source code is Copyright (c) 1999 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp. Word, Excel and Visual Basic are trademarks of Microsoft Corp. True DBGrid is copyright by Apex Software Corporation.

New Visual Basic Site

We are looking for some qualified individuals to work on a new Visual Basic site. The first task is developing a high-quality resource guide for Visual Basic developers. This resource guide will be a well-organized list of web sites that have very good resources about Visual Basic (from beginners stuff through advanced with topics like MTS and ASP). It will gradually expand to include other resources such as free source code and online shopping of development tools. If you are interested in working on a web site dedicated to Visual Basic jump to http://www.allvbstuff.com and fill out the form online. Thanks!


Requirements

In this Issue

This issue demonstrates how to create a non-rectangle shaped form.

cFormShaper

This class modifies the shape of a form by using several API calls to redraw the form. It will allow you to add some special effects to your applications. The basic steps to use this class are to set the FormObject (usually just the Me object) and then set the Shape property to the shape you want the form to appear as.

This class works best with forms that have the BorderStyle property set to 0.

Properties

Public Enum eFormShapes

An enumerator with all the supported form shapes. Currently this class only supports one, eShapeElliptic.

Public FormObject As Form

This should be set to the form that you want to change the shape of. It must be set before any other methods or properties are used.

Public Property Let Shape(eShape As eFormShapes)

Setting this property will automatically change the shape of the form based on the parameter passed in eShape.

Methods

Public Sub CenterForm()

This is a bonus routine to center a form. Since we are changing the shape of a form, we thought a centering routine would be useful.

Public Sub Move(Button As Integer)

This routine is used to allow a captionless (which is the type of form that is required for this routine) to be able to be moved by clicking on the form and dragging the mouse. You will need to call this routine in the Form_MouseDown routine.

Sample Usage

This source code will show how change the shape of a form into an ellipse. This code assumes you have created a new form and changed the BorderStyle property to 0.

Option Explicit

Dim moFormShaper As New cFormShaper

Private Sub cmdQuit_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Set moFormShaper.FormObject = Me      ' sets the form object to shape
    moFormShaper.Shape = eShapeElliptic   ' selects the shape to change the form into.
    moFormShaper.CenterForm      ' centers the form.
End Sub

' Allows movement of the form
Private Sub Form_Mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    moFormShaper.Move Button
End Sub

Source Code

To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0094.html


This document is available on the web

Paid subscribers can view this issue in HTML format. There is no additional source or information in the HTML formatted document. It just looks a little better since we have included some HTML formatting. Just point your browser to link at the top of this document.

Other links

Contact Information

C&D Programming Corp.
PO Box 20128
Floral Park, NY 11002-0128
Phone or Fax: (212) 504-7945
Email: info@codeoftheweek.com
Web: http://www.codeoftheweek.com