pg6111
asked on
How to create a polygon?
How can you place a shape on a form that looks a bracket [ :
_____
| ___|
| |
| |__
|_____|
Can you use the shape control and modify it or do you need to draw it out with Lines or what?
_____
| ___|
| |
| |__
|_____|
Can you use the shape control and modify it or do you need to draw it out with Lines or what?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
We want to draw the polygon as one shape and not three filled-in rectangles. We tried that and then when we moved it around we had a hard time getting it to line up again. It would make it a lot easier if it was just one piece.
How about this one, then? It will have the bracket in just one piece, easily moveable...
Draw a bracket in a drawing program, save it as a GIF file with transparent background and load it into an Image control.
/Ture
Draw a bracket in a drawing program, save it as a GIF file with transparent background and load it into an Image control.
/Ture
The Polygon API lets you draw any shape. This example draws a blue bracket on the form. You can size and move it.
EX:
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function Polygon Lib "gdi32" _
(ByVal hdc As Long, lpPoint As POINTAPI, _
ByVal nCount As Long) As Long
Private poly_verts() As POINTAPI
Private Sub Form_Load()
Dim i As Long
'Define shape
ReDim poly_verts(0 To 7) '8 vertices
poly_verts(0).x = 0
poly_verts(0).y = 0
poly_verts(1).x = 5
poly_verts(1).y = 0
poly_verts(2).x = 5
poly_verts(2).y = 2
poly_verts(3).x = 2
poly_verts(3).y = 2
poly_verts(4).x = 2
poly_verts(4).y = 8
poly_verts(5).x = 5
poly_verts(5).y = 8
poly_verts(6).x = 5
poly_verts(6).y = 10
poly_verts(7).x = 0
poly_verts(7).y = 10
'scale 4x, move 100 pixels from top and left
For i = 0 To 7
poly_verts(i).x = (poly_verts(i).x * 4) + 100
poly_verts(i).y = (poly_verts(i).y * 4) + 100
Next
'Setup draw mode
Me.FillStyle = 0 'Opaque
Me.FillColor = vbBlue
Me.DrawWidth = 1
Me.DrawStyle = 0 'Solid
End Sub
Private Sub Form_Paint()
'Device hdc, address of point array, number of points
Polygon hdc, poly_verts(0), 8
End Sub
EX:
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function Polygon Lib "gdi32" _
(ByVal hdc As Long, lpPoint As POINTAPI, _
ByVal nCount As Long) As Long
Private poly_verts() As POINTAPI
Private Sub Form_Load()
Dim i As Long
'Define shape
ReDim poly_verts(0 To 7) '8 vertices
poly_verts(0).x = 0
poly_verts(0).y = 0
poly_verts(1).x = 5
poly_verts(1).y = 0
poly_verts(2).x = 5
poly_verts(2).y = 2
poly_verts(3).x = 2
poly_verts(3).y = 2
poly_verts(4).x = 2
poly_verts(4).y = 8
poly_verts(5).x = 5
poly_verts(5).y = 8
poly_verts(6).x = 5
poly_verts(6).y = 10
poly_verts(7).x = 0
poly_verts(7).y = 10
'scale 4x, move 100 pixels from top and left
For i = 0 To 7
poly_verts(i).x = (poly_verts(i).x * 4) + 100
poly_verts(i).y = (poly_verts(i).y * 4) + 100
Next
'Setup draw mode
Me.FillStyle = 0 'Opaque
Me.FillColor = vbBlue
Me.DrawWidth = 1
Me.DrawStyle = 0 'Solid
End Sub
Private Sub Form_Paint()
'Device hdc, address of point array, number of points
Polygon hdc, poly_verts(0), 8
End Sub
/Ture