How to Use FillPolygonRgn API to Fill Shape in Visual BasicLast reviewed: June 21, 1995Article ID: Q81470 |
|
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0- Microsoft Visual Basic programming system for Windows, version 1.0
SUMMARYMicrosoft Visual Basic versions 2.0 and later for Windows include the Shape control which can be used for creating and filling six different geometric shapes. Alternatively, you can create a polygon region on a form or picture and fill it with a color, using the CreatePolygonRgn and FillRgn Windows API calls to draw and fill areas of the screen with color. Geometric shapes not provided with the Shape control, such as a triangle, can be created using this method. More Information: To draw a polygon on a form or picture control, you can use the Polygon API call; this will draw the edge of the polygon. You can then use CreatePolygonRgn to create an area that you can paint and use FillRgn to fill it with a color. Using these Windows API calls allows you to pick the points, the number of points, and to choose the color or brush to fill with. The API calls used in the following example should be declared in the general Declarations section of your form. They are as follows:
API Call Description CreatePolygonRgn Creates a polygonal region
GetStockObject Retrieves a handle to one of the predefined stock
pens, brushes, or fonts
FillRgn Fills the region specified by the hRgn parameter
with the brush specified by the hBrush parameter
Polygon Draws a polygon consisting of two or more points
connected by lines
Code ExampleThe following code example shows how to create a black triangle on a form. To change the program to create other shapes, add points to the array.
NOTE: If you try to fill a region with coordinates beyond the visible form, the CreatePolygonRgn function call will return a zero, meaning it was unsuccessful. The FillRgn will not work if the CreatePolygonRgn function was unsuccessful. All you will see is the outline created by the Polygon function. You should make certain that the vertices are all within the viewable form.
|
Additional reference words: 1.00 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |