GDI Examples


Example 1:

//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
    PaintBox1->Canvas->Brush->Color = clBlack;
    PaintBox1->Canvas->Rectangle(0, 0, ClientWidth, ClientHeight);

    HDC hDC = PaintBox1->Canvas->Handle;
    SetMapMode(hDC, MM_LOENGLISH);
    SetViewportOrgEx(hDC, PaintBox1->Left, 455, NULL);
                              
    PaintBox1->Canvas->Pen->Color = clWhite;
    PaintBox1->Canvas->MoveTo(21, 20);
    PaintBox1->Canvas->LineTo(21, 75);
    // Up arrow
    PaintBox1->Canvas->MoveTo(16, 75);
    PaintBox1->Canvas->LineTo(21, 90);
    PaintBox1->Canvas->LineTo(26, 75);
    PaintBox1->Canvas->LineTo(16, 75);

    PaintBox1->Canvas->MoveTo(21, 22);
    PaintBox1->Canvas->LineTo(75, 22);
    // Right arrow
    PaintBox1->Canvas->MoveTo(75, 17);								
    PaintBox1->Canvas->LineTo(90, 22);
    PaintBox1->Canvas->LineTo(75, 27);
    PaintBox1->Canvas->LineTo(75, 17);

    PaintBox1->Canvas->Font->Name = "Tahoma";
    PaintBox1->Canvas->Font->Color = clWhite;
    PaintBox1->Canvas->Font->Size = 14;
    PaintBox1->Canvas->TextOut(16, 114, 'Y');
    PaintBox1->Canvas->TextOut(100, 32, 'X');

    PaintBox1->Canvas->Rectangle(15, 15, 30, 30);
}
//---------------------------------------------------------------------------					


Line Grid

//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
    Canvas->Pen->Color = clMaroon;
    Canvas->Brush->Color = clBlack;
    Canvas->Rectangle(0, 0, Width, Height);

    Canvas->Pen->Color = clBlue;

    for(int x = 0; x < Width; x += 20)
    {
        Canvas->MoveTo(x, 0);
        Canvas->LineTo(x, Height);
    }

    for(int y = 0; y < Height; y += 20)
    {
        Canvas->MoveTo(0, y);
        Canvas->LineTo(Width, y);
    }
}
//---------------------------------------------------------------------------


Point Grid

//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
    Canvas->Pen->Color = clBlack;
    Canvas->Brush->Color = clBlack;
    Canvas->Rectangle(0, 0, Width, Height);

    Canvas->Pen->Color = clWhite;

    for(int x = 0; x < Width; x += 20)
    {
        for(int y = 0; y < Height; y += 20)
        {
            Canvas->Pixels[x][y] = clWhite;
        }
    }
}
//---------------------------------------------------------------------------

 

 


Copyright 2004-2007 FunctionX, Inc.