Re: Delphi drawgrid

Posted by Jenny on April 18, 2007

In Reply to Delphi 4 Help! posted by Graham Roberts on April 17, 2007

: I am programming a school project in delphi 4. It is a game based on the popular game "peg solitaire". So far it has went quite well. I have completed the HCI, the board (a delphi draw grid) is in place. Now, i need to "draw images to it". As it stands, i have it loading with the numbers 1, 2 and 0. 0 is blank as in not part of the board, 1 is a peg and 2 is a "hole"... as shown below:

: [url=htp://]Click Here For Screenshot[/url]

: my code for this section is:

: [quote]mplementation
: {$R *.DFM}
: uses Unit2, Unit3, Unit4;

: type boardarray= array[0..6,0..6] of byte; //activate board array

: const
: mainboard:boardarray=( (0,0,1,1,1,0,0),
: (0,0,1,1,1,0,0),
: (1,1,1,1,1,1,1),
: (1,1,1,2,1,1,1),
: (1,1,1,1,1,1,1),
: (0,0,1,1,1,0,0),
: (0,0,1,1,1,0,0)) ;[/quote]

: and

: [quote]procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
: Rect: TRect; State: TGridDrawState);
: begin
: DrawGrid1.Canvas.TextOut(Rect.Left, Rect.Top,inttostr(mainboard[ACol, ARow]));
: end;[/quote]

: I would like to replace the 0 with an image (image0.bmp), the 1 with an image (image1.bmp) and the 2 with an image (image 2.bmp), but havent got a clue what to do.

: Hope one of you guys knows delphi and can help.

: Cheers as always!

: -Graham


When I try to view your "as shown below" screenshot, I got: "Sorry, but you do not have permission to use this feature". I suggest you try your links before you post a message...;) Anyways, let's try...;)

Where are the files image0.bmp, image1.bmp, image2.bmp? In the same directory as the "application" (the exe-file) or somewhere else?

The solution isn't difficult, it's jut about knowing where the image files are.

Related articles


Follow Ups