• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

Polygon OCX

I'm looking for something that will basically act like the Shape control that comes with Visual Basic, but will let me do more shapes than that.  Actually I only need to be able to do four-sided shapes where I can define where all four corners will be.  Is there anything out there that can help me?  Preferrably free, of course...

Thanks in advance!
  • 2
1 Solution
Richie_SimonettiIT OperationsCommented:
see if this could help
' from www.allapi.net
Private Type COORD
    x As Long
    y As Long
End Type
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Const WINDING = 2 ' constants for FillMode.
Const BLACKBRUSH = 4 ' Constant for brush type.
Private Sub Form_Paint()
    'KPD-Team 1999
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long
    ' Number of vertices in polygon.
    NumCoords = 3
    ' Set scalemode to pixels to set up points of triangle.
    Me.ScaleMode = vbPixels
    ' Assign values to points.
    poly(1).x = Form1.ScaleWidth / 2
    poly(1).y = Form1.ScaleHeight / 2
    poly(2).x = Form1.ScaleWidth / 4
    poly(2).y = 3 * Form1.ScaleHeight / 4
    poly(3).x = 3 * Form1.ScaleWidth / 4
    poly(3).y = 3 * Form1.ScaleHeight / 4
    ' Polygon function creates unfilled polygon on screen.
    ' Remark FillRgn statement to see results.
    Polygon Me.hdc, poly(1), NumCoords
    ' Gets stock black brush.
    hBrush = GetStockObject(BLACKBRUSH)
    ' Creates region to fill with color.
    hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
    ' If the creation of the region was successful then color.
    If hRgn Then FillRgn Me.hdc, hRgn, hBrush
    DeleteObject hRgn
End Sub
Private Sub Form_Resize()
End Sub

Richie_SimonettiIT OperationsCommented:
' from same source:
Option Explicit
Private Type POINTAPI
        x As Long
        y As Long
End Type
Private Declare Function CreatePolyPolygonRgn Lib "gdi32" (lpPoint As POINTAPI, lpPolyCounts As Long, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function InvertRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Form_Load()
    'KPD-Team 1999
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Const ALTERNATE = 1

    Me.AutoRedraw = True
    ' Invert the points lying within a multi-polygonal region on window Form1.  The
    ' region is made up of a triangle and a diamond.  The triangle has vertices (25,25), (50,50),
    ' and (25,50).  The diamond has vertices (150,150), (200,200), (150,250), and (100,200).
    Dim vertex(0 To 6) As POINTAPI ' holds vertices of each polygon
    Dim numvertices(0 To 1) As Long  ' holds how many vertices belong to each polygon
    Dim hRgn As Long  ' handle to the multi-polygonal region
    Dim retval As Long  ' return value

    ' Load the vertices of the triangle into the vertex array.
    vertex(0).x = 25: vertex(0).y = 25  ' 1st point: (25,25)
    vertex(1).x = 50: vertex(1).y = 50  ' 2nd point: (50,50)
    vertex(2).x = 25: vertex(2).y = 50  ' 3rd point: (25,50)
    numvertices(0) = 3  ' three vertices for the triangle

    ' Load the vertices of the diamond into the vertex array.
    vertex(3).x = 150: vertex(3).y = 150  ' 1st point: (150,150)
    vertex(4).x = 200: vertex(4).y = 200  ' 2nd point: (200,200)
    vertex(5).x = 150: vertex(5).y = 250  ' 3rd point: (150,250)
    vertex(6).x = 100: vertex(6).y = 200  ' 4th point: (100,200)
    numvertices(1) = 4  ' four vertices for the triangle

    ' Create the multi-polygonal region and get a handle to it.
    hRgn = CreatePolyPolygonRgn(vertex(0), numvertices(0), 2, ALTERNATE)
    ' Invert the pixels within this region on Form1.
    retval = InvertRgn(Me.hdc, hRgn)
    ' Delete the region to free up resources.
    retval = DeleteObject(hRgn)
End Sub

Hi pyrames,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Richie_Simonetti's comment(s) as an answer.

pyrames, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
DanRollins -- EE database cleanup volunteer
Comment from expert accepted as answer

E-E Admin

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now