The following example sets the world transformation and the page transformation of a
Graphics object. The page unit and the page scale both belong to the page transformation. The code sets the page unit to millimeters and sets the page scale to 10. The call to the
GdipDrawRectangle method draws a rectangle that has a width of 3 centimeters (UnitMillimeter along with a scaling factor of 10) and a height of 2 centimeters. The rectangle is translated 4 centimeters to the right and 1 centimeter down by the world transformation.
C++
VOID Example_SetPageScale(HDC hdc)
{
Graphics graphics(hdc);
// Set the world transformation.
graphics.TranslateTransform(4.0f, 1.0f);
// Set the page transformation.
graphics.SetPageUnit(UnitMillimeter);
graphics.SetPageScale(10.0f);
Pen pen(Color(255, 0, 0, 0), 0.0f);
graphics.DrawRectangle(&pen, 0, 0, 3, 2);
}
PowerBASIC
SUB GDIP_SetPageScale (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Set the world transformation.
hStatus = GdipTranslateWorldTransform(pGraphics, 4.0, 1.0, %MatrixOrderPrepend)
' // Set the page transformation.
hStatus = GdipSetPageUnit(pGraphics, %UnitMillimeter)
hStatus = GdipSetPageScale(pGraphics, 10.0)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 0, %UnitWorld, pPen)
hStatus = GdipDrawRectangle(pGraphics, pPen, 0, 0, 3, 2)
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipSetPageScale.png)