Results 1 to 3 of 3

Thread: [RESOLVED] (VB6) Polygon API - How to delete previous drawn polygon ?

  1. #1

    Thread Starter
    Lively Member amolt's Avatar
    Join Date
    Aug 2006
    Location
    INDIA
    Posts
    80

    Resolved [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 ......

  2. #2
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    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

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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:
    1. Private Type COORD
    2.     x As Long
    3.     y As Long
    4. End Type
    5.  
    6. Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
    7. Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
    8. Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
    9. Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
    10.  
    11. Const ALTERNATE = 1 '-- ALTERNATE and WINDING are
    12. Const WINDING = 2 '-- constants for FillMode.
    13. Const BLACKBRUSH = 4 '-- Constant for brush type.
    14. Public hRgn As Long
    15.  
    16. Private Sub Command1_Click()
    17.     Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long
    18.     Me.Cls
    19.    
    20.     '-- Number of vertices in polygon.
    21.     NumCoords = 3
    22.    
    23.     '-- Set scalemode to pixels to set up points of triangle.
    24.     Me.ScaleMode = vbPixels
    25.    
    26.     '-- Assign values to points.
    27.     poly(1).x = Form1.ScaleWidth / 2
    28.     poly(1).y = Form1.ScaleHeight / 2
    29.     poly(2).x = Form1.ScaleWidth / 4
    30.     poly(2).y = 3 * Form1.ScaleHeight / 4
    31.     poly(3).x = 3 * Form1.ScaleWidth / 4
    32.     poly(3).y = 3 * Form1.ScaleHeight / 4
    33.    
    34.     '-- Polygon function creates unfilled polygon on screen.
    35.     '-- Remark FillRgn statement to see results.
    36.     Polygon Me.hdc, poly(1), NumCoords
    37.     '-- Gets stock black brush.
    38.     hBrush = GetStockObject(BLACKBRUSH)
    39.     '-- Creates region to fill with color.
    40.     hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
    41.     '-- If the creation of the region was successful then color.
    42.     If hRgn Then FillRgn Me.hdc, hRgn, hBrush
    43.    
    44.     MsgBox "The Polygon will be cleared now" '<==========
    45.     '-- Clears the polygon
    46.     Me.Cls
    47. End Sub
    Last edited by Siddharth Rout; Feb 12th, 2009 at 01:45 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width