1 Attachment(s)
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:
Option Explicit
Private Type COORD
x As Long
y As Long
End Type
Dim Region() As COORD
Dim iXBorder As Long
Dim iYBorder As Long
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount 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 ALTERNATE = 1 ' ALTERNATE and WINDING are
Const WINDING = 2 ' constants for FillMode.
Const BLACKBRUSH = 4 ' Constant for brush type.
Private Sub drawTrapezoid(x As Long, y As Long, Width As Long, Height As Long)
Width = Width - iXBorder
ReDim Preserve Region(1 To 4)
Dim NumCoords As Long, hBrush As Long, hRgn As Long
' Number of vertices in polygon.
NumCoords = 4
With Region(1)
.x = x + iXBorder
.y = y
End With
With Region(2)
.x = x
.y = y + Height
End With
With Region(3)
.x = x + iXBorder + Width
.y = y + Height
End With
With Region(4)
.x = x + Width
.y = y
End With
hBrush = GetStockObject(BLACKBRUSH)
' Creates region to fill with color.
hRgn = CreatePolygonRgn(Region(1), NumCoords, ALTERNATE)
' If the creation of the region was successful then color.
If hRgn Then
Dim Ret As Long
Ret = SetWindowRgn(Me.hWnd, hRgn, True)
End If
DeleteObject hRgn
End Sub
Private Sub Form_Load()
iXBorder = 10
drawTrapezoid 40, 40, ScaleX(1995, vbTwips, vbPixels), ScaleX(285, vbTwips, vbPixels)
End Sub
Let me show what i mean:http://www.vbforums.com/attachment.p...postid=1772416