Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

The Canvas

polsolpolsol Posts: 6Member
When Delphi "draws" on a canvas, such as a cell in a grid, is this canvas (i.e. the cell) an individual canvas or is it a "sub - section" of a larger canvas (the grid itself)? Or, is the grid a collection of canvases (cells)? In effect is the canvas (cell) an actual Window (as per WIndows terminology)?

Thanks, I am a little confused on this topic right now. Don't normally go down to this type of level in my progs.

Regards,
Tony

Comments

  • zibadianzibadian Posts: 6,349Member
    : When Delphi "draws" on a canvas, such as a cell in a grid, is this canvas (i.e. the cell) an individual canvas or is it a "sub - section" of a larger canvas (the grid itself)? Or, is the grid a collection of canvases (cells)? In effect is the canvas (cell) an actual Window (as per WIndows terminology)?
    :
    : Thanks, I am a little confused on this topic right now. Don't normally go down to this type of level in my progs.
    :
    : Regards,
    : Tony
    :
    The grid has a single canvas, on which small rectangles are defined as cells. A lot of controls (not all sadly) have a canvas at some level of visibility (protected to public). This object is nothing more than a wrapper around several windows drawing API functions. Thanks to this wrapper a lot of drawing can be done using simple Delphi statements instead of weird API functions, which need handles to operate. The actual drawing of the control is handled in the protected method Paint(). Programmers can override this method to provide for their own drawing style. Most grids allow their programmers to change the way the cells are drawn using an event, which is called in the Paint() method. Thus a pseudo-implementation of the TGrid.Paint() might look like this:
    [code]
    for r := 0 to RowCount-1 do
    for c := 0 to ColCount-1 do // loop all cells
    if CellIsVisible(r, c) then begin // check if visible
    if Assigned(OnDrawCell) then // check if OnDrawCell has been written
    DrawCell(Self, r, c, GetCellRect)
    else // else draw the cell normally
    DefaultDrawCell(Self, r, c, GetCellRect);
    end;
    [/code]

    I hope this clears thing up a bit.

    Note: You could write an OnDrawCell(), which writes to the canvas outside the "box" and see if you get some weird result.
Sign In or Register to comment.