Pages

Wednesday, December 28, 2011

How to create colored stringgrid in delphi

To make our program look more beautiful, we often add some functionality to handle it's look as well as stringgrid. One way to enhance the appearance is to set it's into the colorful. Below is the script to do that :
var
  dx: Integer;
begin
  with (Sender as TStringGrid) do
  begin
    if (ACol = 0) or (ARow = 0) then
      Canvas.Brush.Color := clBtnFace
    else
    begin
      case ACol of
        1: Canvas.Font.Color := clBlack;
        2: Canvas.Font.Color := clBlue;
      end;
      if ARow mod 2 = 0 then
        Canvas.Brush.Color := $00E1FFF9
      else
        Canvas.Brush.Color := $00FFEBDF;
      Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]);
      Canvas.FrameRect(Rect);
    end;
  end;
end;
 
Paste that function on event OnDrawCell in stringgrid. The result of your code will look like this :
alternate stringgrid

No comments:

Post a Comment

Don't Forget To Join Our Community
×
Widget