The following example creates an
AdjustableArrowCap,
pMyArrowCap, and sets the width of the cap to 10 pixels. The code then creates a
Pen, assigns
pMyArrowCap as the ending line cap for this
Pen, and draws a capped line. Next, the code sets the width to 15 pixels, reassigns the arrow cap to the pen, and draws a new capped line.
C++
VOID Example_SetWidth(HDC hdc)
{
Graphics graphics(hdc);
// Create an AdjustableArrowCap, and set the middle inset to 5.
AdjustableArrowCap myArrow(10, 10, true);
// Create a Pen, and assign myArrow as the end cap.
Pen arrowPen(Color(255, 0, 0, 0));
arrowPen.SetCustomEndCap(&myArrow);
// Draw a line using arrowPen.
graphics.DrawLine(&arrowPen, Point(0, 0), Point(100, 100));
// Set the cap to the new width, and reassign the arrow cap
// to the pen object.
myArrow.SetWidth(15.7f);
arrowPen.SetCustomEndCap(&myArrow);
// Draw a line with new cap.
graphics.DrawLine(&arrowPen, Point(0, 40), Point(100, 140));
}
PowerBASIC
SUB GDIP_SetWidth (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pArrowPen AS DWORD
LOCAL pMyArrowCap AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create an AdjustableArrowCap.
hStatus = GdipCreateAdjustableArrowCap(10, 10, %TRUE, pMyArrowCap)
' // Create a Pen, and assign pMyArrowCap as the end cap.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1.0!, %UnitWorld, pArrowPen)
hStatus = GdipSetPenCustomEndCap(pArrowPen, pMyArrowCap)
' // Draw a line using pArrowPen.
hStatus = GdipDrawLineI(pGraphics, pArrowPen, 0, 0, 100, 100)
' // Set the cap to the new width, and reassign the arrow cap to the pen object.
hStatus = GdipSetAdjustableArrowCapWidth(pMyArrowCap, 15.7!)
hStatus = GdipSetPenCustomEndCap(pArrowPen, pMyArrowCap)
' // Draw a line with new cap.
hStatus = GdipDrawLineI(pGraphics, pArrowPen, 0, 40, 100, 140)
' // Cleanup
IF pMyArrowCap THEN GdipDeleteCustomLineCap(pMyArrowCap)
IF pArrowPen THEN GdipDeletePen(pArrowPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipSetAdjustableArrowCapWidth.png)