The following example draws two rectangles: one measured in pixels and one measured in inches.
C++
VOID Example_SetPageUnit(HDC hdc)
{
Graphics graphics(hdc);
// Set the page units to pixels, and draw a rectangle.
graphics.SetPageUnit(UnitPixel);
Pen blackPen(Color(255, 0, 0, 0), 0.0f);
graphics.DrawRectangle(&blackPen, 0, 0, 100, 100);
// Set the page units to inches, and draw a rectangle.
graphics.SetPageUnit(UnitInch);
Pen bluePen(Color(255, 0, 0, 255), 0.0f);
graphics.DrawRectangle(&bluePen, 2, 0, 1, 1);
}
PowerBASIC
SUB GDIP_SetPageUnit (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pBlackPen AS DWORD
LOCAL pBluePen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Set the page units to pixels, and draw a rectangle.
hStatus = GdipSetPageUnit(pGraphics, %UnitMillimeter)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 0, %UnitWorld, pBlackPen)
hStatus = GdipDrawRectangle(pGraphics, pBlackPen, 0, 0, 100, 100)
' // Set the page units to inches, and draw a rectangle.
hStatus = GdipSetPageUnit(pGraphics, %Unitinch)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 0, %UnitWorld, pBluePen)
hStatus = GdipDrawRectangle(pGraphics, pBlackPen, 2, 0, 1, 1)
' // Cleanup
IF pBlackPen THEN GdipDeletePen(pBlackPen)
IF pBluePen THEN GdipDeletePen(pBluePen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipSetPageUnit.png)