The following example draws six of the available hatch styles.
C++
VOID Example_HatchBrushConstructor(HDC hdc)
{
Graphics graphics(hdc);
// Set colors.
Color black(255,0,0,0);
Color white(255,255,255,255);
// Set and then draw the first hatch style.
HatchBrush brush(HatchStyleHorizontal, black, white);
graphics.FillRectangle(&brush, 20, 20, 100, 50);
// Set and then draw the second hatch style.
HatchBrush brush1(HatchStyleVertical, black, white);
graphics.FillRectangle(&brush1, 120, 20, 100, 50);
// Set and then draw the third hatch style.
HatchBrush brush2(HatchStyleForwardDiagonal, black, white);
graphics.FillRectangle(&brush2, 220, 20, 100, 50);
// Set and then draw the fourth hatch style.
HatchBrush brush3(HatchStyleBackwardDiagonal, black, white);
graphics.FillRectangle(&brush3, 320, 20, 100, 50);
// Set and then draw the fifth hatch style.
HatchBrush brush4(HatchStyleCross, black, white);
graphics.FillRectangle(&brush4, 420, 20, 100, 50);
// Set and then draw the sixth hatch style.
HatchBrush brush5(HatchStyleDiagonalCross, black, white);
graphics.FillRectangle(&brush5, 520, 20, 100, 50);
}
PowerBASIC
SUB GDIP_CreateHatchBrush (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pColorBlack AS DWORD
LOCAL pColorWhite AS DWORD
LOCAL pBrush AS DWORD
LOCAL pBrush1 AS DWORD
LOCAL pBrush2 AS DWORD
LOCAL pBrush3 AS DWORD
LOCAL pBrush4 AS DWORD
LOCAL pBrush5 AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Set colors.
pColorBlack = GDIP_ARGB(255, 0, 0, 0)
pColorWhite = GDIP_ARGB(255, 255, 255, 255)
' // Set and then draw the first hatch style.
hStatus = GdipCreateHatchBrush(%HatchStyleHorizontal, pColorBlack, pColorWhite, pBrush)
hStatus = GdipFillRectangle(pGraphics, pBrush, 20, 20, 100, 50)
' // Set and then draw the second hatch style.
hStatus = GdipCreateHatchBrush(%HatchStyleVertical, pColorBlack, pColorWhite, pBrush1)
hStatus = GdipFillRectangle(pGraphics, pBrush1, 120, 20, 100, 50)
' // Set and then draw the third hatch style.
hStatus = GdipCreateHatchBrush(%HatchStyleForwardDiagonal, pColorBlack, pColorWhite, pBrush2)
hStatus = GdipFillRectangle(pGraphics, pBrush2, 220, 20, 100, 50)
' // Set and then draw the fourth hatch style.
hStatus = GdipCreateHatchBrush(%HatchStyleBackwardDiagonal, pColorBlack, pColorWhite, pBrush3)
hStatus = GdipFillRectangle(pGraphics, pBrush3, 20, 100, 100, 50)
' // Set and then draw the fifth hatch style.
hStatus = GdipCreateHatchBrush(%HatchStyleCross, pColorBlack, pColorWhite, pBrush4)
hStatus = GdipFillRectangle(pGraphics, pBrush4, 120, 100, 100, 50)
' // Set and then draw the sixth hatch style.
hStatus = GdipCreateHatchBrush(%HatchStyleDiagonalCross, pColorBlack, pColorWhite, pBrush5)
hStatus = GdipFillRectangle(pGraphics, pBrush5, 220, 100, 100, 50)
' // Cleanup
IF pBrush THEN GdipDeleteBrush(pBrush)
IF pBrush1 THEN GdipDeleteBrush(pBrush1)
IF pBrush2 THEN GdipDeleteBrush(pBrush2)
IF pBrush3 THEN GdipDeleteBrush(pBrush3)
IF pBrush4 THEN GdipDeleteBrush(pBrush4)
IF pBrush5 THEN GdipDeleteBrush(pBrush5)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipCreateHatchBrush.png)