Posted by webmaster Guido on August 17, 2003
In Reply to: annoying stringgrid focus posted by Ed Marmier, p12332 on August
12, 2003 The default behavior of a Delphi stringgrid is as follows: - If the stringgrid is focused (if it is the active component), then a focus rectangle is drawn
around the *selected* cell and its colors are the default colors for the stringgrid, usually black text
on a white background. At startup of the program, this is the topleft non-fixed cell: cell [0,0] if
there
is no
fixed row nor
fixed column,
with
1 fixed
column and 1 fixed
row this is cell[1,1], and so on... To avoid the "highlight" coloring (white-on-dark-blue) of a cell, we can redraw that cell in another color ourselves in the OnDrawCell event handler. By the way, you don't have to set the Defaultdrawing property to "false"; even with its default state of "true", you get the OnDrawCell event. An example: procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin with StringGrid1.Canvas do begin // Fill rectangle with background color of grid Brush.Color := StringGrid1.Color; FillRect(Rect); // Next, draw the text in the rectangle Font.Color := StringGrid1.Font.Color; TextOut(Rect.Left + 2, Rect.Top + 2, StringGrid2.Cells[ACol, ARow]); end; end; |