Color of Dbgrid font in Delphi Berlin

Asked

Viewed 530 times

0

I’m having trouble changing the text color of the records displayed in Dbggrid in Delphi Berlin (10.1 update 1). When trying to change the font color and turn on italics and bold, all records appear correctly except the selected record that displays duplicate text, one with the font changes and the other without any change. It is worth noting that the font below is only for testing so it changes the color of all records in the system there will be situations where this color will be changed or not. Follows below excerpt of the code and image that illustrates the problem.

procedure TForm2.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  TDBGrid(Sender).Canvas.Font.Style := [fsItalic, fsBold];
  TDBGrid(Sender).Canvas.Font.Color := clMaroon;

  TDBGrid(Sender).Canvas.FillRect(Rect);
  TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

inserir a descrição da imagem aqui

1 answer

0


Even posting the doubt in Delphi Experts,I did not get a satisfactory answer, but I will go here the two solutions found:

1: Avoid formatting code whenever the record is selected. This way the duplicate text does not occur because the system does not generate the formatted text. Ex:

procedure TForm2.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if gdSelected in State then
    Exit;

  TDBGrid(Sender).Canvas.Font.Style := [fsItalic, fsBold];
  TDBGrid(Sender).Canvas.Font.Color := clMaroon;

  TDBGrid(Sender).Canvas.FillRect(Rect);
  TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

2: The DBGrig of the younger Delphis (I can’t remember from which version) owns a property called DrawingStyle that in Berlin comes set with gdsThemed, This indicates to the system that should generate Dbgrid according to the Windows theme, with this property the form of the text presents the error I mentioned. If this property is changed to gdsClassic Dbgird will not follow the Windows theme but will properly format the contents of use cells.

It is up to each of you to choose the best way. If there is another way please inform as you would like to try.

  • What Benjamin Said is true I went through this problem and in this website I found a way to fix or ease the situation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.