Results 1 to 14 of 14

Thread: Draw it Symmetrically (Resolved)

Threaded View

  1. #1

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Resolved Draw it Symmetrically (Resolved)

    I am drawing a trapezoid using regions... But the problem is that it isn't symmetrical.. What am I doing wrong?

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type COORD
    4.  x As Long
    5.  y As Long
    6. End Type
    7.  
    8. Dim Region() As COORD
    9. Dim iXBorder As Long
    10. Dim iYBorder As Long
    11.  
    12. Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
    13. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    14. Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
    15. Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
    16. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    17.  
    18. Const ALTERNATE = 1 ' ALTERNATE and WINDING are
    19. Const WINDING = 2 ' constants for FillMode.
    20. Const BLACKBRUSH = 4 ' Constant for brush type.
    21.  
    22. Private Sub drawTrapezoid(x As Long, y As Long, Width As Long, Height As Long)
    23.  Width = Width - iXBorder
    24.  
    25.  ReDim Preserve Region(1 To 4)
    26.  Dim NumCoords As Long, hBrush As Long, hRgn As Long
    27.  
    28.  ' Number of vertices in polygon.
    29.  NumCoords = 4
    30.  
    31.  With Region(1)
    32.   .x = x + iXBorder
    33.   .y = y
    34.  End With
    35.  With Region(2)
    36.   .x = x
    37.   .y = y + Height
    38.  End With
    39.  With Region(3)
    40.   .x = x + iXBorder + Width
    41.   .y = y + Height
    42.  End With
    43.  With Region(4)
    44.   .x = x + Width
    45.   .y = y
    46.  End With
    47.  
    48.  hBrush = GetStockObject(BLACKBRUSH)
    49.  ' Creates region to fill with color.
    50.  hRgn = CreatePolygonRgn(Region(1), NumCoords, ALTERNATE)
    51.  ' If the creation of the region was successful then color.
    52.  If hRgn Then
    53.   Dim Ret As Long
    54.   Ret = SetWindowRgn(Me.hWnd, hRgn, True)
    55.  End If
    56.    
    57.  DeleteObject hRgn
    58. End Sub
    59.  
    60. Private Sub Form_Load()
    61.  iXBorder = 10
    62.  drawTrapezoid 40, 40, ScaleX(1995, vbTwips, vbPixels), ScaleX(285, vbTwips, vbPixels)
    63. End Sub

    Let me show what i mean:
    Attached Images Attached Images  
    Last edited by Tec-Nico; Oct 3rd, 2004 at 01:49 PM.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

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