[RESOLVED] (VB6) Polygon API - How to delete previous drawn polygon ?
Hello Everyone,
I draw a Polygon in my application on PictureBox as in code below
Code:
Picture1.Cls
Picture1.DrawStyle = vbDashDot
Picture1.FillStyle = vbCross
Picture1.FillColor = vbGreen
If mPoints > 2 Then
Polygon hdc, m_Points(1), mPoints
End If
Now if i choose other feature than drawing polygon, I need to reset all previously drawn polygon, So I tried by Picture1.Cls again .. but the problem is when I draw another feature or Polygon again the previous polygon is again gets visible.
How should I am able to delete this drawn Polygon?
Wishing for the help ASAP ....
Thanks ......
Re: (VB6) Polygon API - How to delete previous drawn polygon ?
amolt
I'm a VB6 guy, but not an API guy, and am not familiar with
Polygon statement.
Nonetheless, PB1.Cls is something I'm familiar with, as are
PB1.Drawstyle, etc. So, my possible contribution here will
be logic-based -- and I have the following observation:
The PB1.Cls seems fine. But, the data being used to generate
the polygon (contained in m_Points(1) I assume) -- does it
change too? Otherwise, if it is same data as before, natch,
the same polygon will be redrawn (ie, "gets visible")
HTH
Spoo
Re: (VB6) Polygon API - How to delete previous drawn polygon ?
This will clear any objects in the form...
Me.Cls
See the example below. Create a blank form and create a commandbutton.
vb Code:
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
Const ALTERNATE = 1 '-- ALTERNATE and WINDING are
Const WINDING = 2 '-- constants for FillMode.
Const BLACKBRUSH = 4 '-- Constant for brush type.
Public hRgn As Long
Private Sub Command1_Click()
Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long
Me.Cls
'-- 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
MsgBox "The Polygon will be cleared now" '<==========
'-- Clears the polygon
Me.Cls
End Sub