Sudoku: use OnPrepareCanvas instead of OnDrawCell. Adjust background-color, so text is readable.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7221 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
lazarus-bart
2020-01-04 15:02:45 +00:00
parent c95ae4a197
commit 20fbfe933f
2 changed files with 21 additions and 23 deletions

View File

@ -31,7 +31,7 @@ object Form1: TForm1
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goSmoothScroll]
RowCount = 9
TabOrder = 2
OnDrawCell = StringGrid1DrawCell
OnPrepareCanvas = StringGrid1PrepareCanvas
OnSetEditText = StringGrid1SetEditText
end
object ButtonFill: TButton

View File

@ -41,8 +41,8 @@ type
StringGrid1: TStringGrid;
procedure ButtonFillClick(Sender: TObject);
procedure ButtonSolveClick(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
aRect: TRect; aState: TGridDrawState);
procedure StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: string);
private
@ -89,31 +89,29 @@ begin
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
aRect: TRect; aState: TGridDrawState);
procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
var
Kleur: Boolean;
NeedsColor: Boolean;
begin
Kleur := False;
if Col in [0..2, 6..8] then begin
if Row in [0..2, 6..8] then begin
Kleur := True;
NeedsColor := False;
if aCol in [0..2, 6..8] then
begin
if aRow in [0..2, 6..8] then
begin
NeedsColor := True;
end;
end else begin
if Row in [3..5] then begin
Kleur := True;
end
else
begin
if aRow in [3..5] then
begin
NeedsColor := True;
end;
end;
if Kleur then begin
inc(aRect.Top, 1);
inc(aRect.Left, 1);
dec(aRect.Bottom, 1);
dec(aRect.Right, 1);
StringGrid1.Canvas.Brush.Color := clLtGray;
StringGrid1.Canvas.FillRect(aRect);
// Volgende regel is alleen in Delphi noodzakelijk.
// StringGrid1.Canvas.TextOut(aRect.Left, aRect.Top, StringGrid1.Cells[Col, Row]);
end;
if NeedsColor then
(Sender as TStringGrid).Canvas.Brush.Color := $00EEEEEE;
end;
procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;