Put this Code in a standard module.
then you can use this to draw your triangle. to draw a blue triangle in Picture1 with corners at 50,0 0,100 and 100,100 just typeCode:Option Explicit Private Type POINTAPI x As Long y As Long End Type Private Const POLYFILL_LAST = 2 Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode 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 DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long Public Function FillTriangle(hdc As Long, X1 As Long, Y1 As Long, X2 As Long, Y2 As Long, X3 As Long, Y3 As Long, Colour As ColorConstants) Dim apiPoints(0 To 2) As POINTAPI Dim hRgn As Long Dim hBrush As Long apiPoints(0).x = X1 apiPoints(1).x = X2 apiPoints(2).x = X3 apiPoints(0).y = Y1 apiPoints(1).y = Y2 apiPoints(2).y = Y3 hRgn = CreatePolygonRgn(apiPoints(0), 3, POLYFILL_LAST) hBrush = CreateSolidBrush(Colour) FillRgn hdc, hRgn, hBrush DeleteObject hRgn deleteobjet hBrush End Function
N.B. the measurements must be in pixels, use the ScaleY and ScaleY functions to help convert.Code:FillTriangle Picture1.hdc, 50, 0, 0, 100, 100, 100, vbBlue
Hope this helps


Reply With Quote