![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
|
Нужна функция раскраски ячейки (фон и шрифт) в зависимости от переданных параметров.
Код ниже раскрашивает, но при выделении мышкой возвращается стандартное оформление. Как сделать, чтобы раскраска оставалась при любых манипуляциях? OnDrawCell использовать только чтобы сохранять раскраску. Код:
procedure ColorGrid(Grid:TStringGrid;ACol,ARow:Integer;Alive:Boolean;Exp:Integer);
var
Rect:TRect;
begin
rect:=Grid.CellRect(ACol,ARow);
case Exp of
-1: Grid.Canvas.Font.Color:=RGB(255,0,0);//min
0: Grid.Canvas.Font.Color:=RGB(0,0,0);//avg
1: Grid.Canvas.Font.Color:=RGB(0,255,0);//max
end;
Grid.Canvas.TextRect(rect,5,5,Grid.Cells[ACol,ARow]);//text color
case Alive of
false: Grid.Canvas.Brush.Color:=RGB(255,153,153);//cell color
true: Grid.Canvas.Brush.Color:=RGB(0,255,179);
end;
Grid.Canvas.FillRect(rect);
Grid.Canvas.TextOut(Rect.Left+2, Rect.Top+2, Grid.Cells[ACol, ARow]);
end;
Спасибо. Последний раз редактировалось kossr, 05.04.2013 в 17:05. |
|
#2
|
|||
|
|||
|
Код:
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); begin CanSelect := False; end; Спасибо за многочисленные ответы. Последний раз редактировалось lmikle, 05.04.2013 в 19:03. |
|
#3
|
||||
|
||||
|
Оффтоп:
Цитата:
По теме: Цитата:
Код:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
fcl, bcl: TColor;
fcs: TFontStyles;
begin
with StringGrid1.Canvas do
begin
fcl:= Font.Color; fcs:= Font.Style; bcl:= Brush.Color;
if gdSelected in State then
begin
Font.Color:= TColor($FFFFFF);
Font.Style:= Font.Style + [fsBold];
Brush.Color:= clGreen;
end else
if ARow < StringGrid1.FixedRows then
begin
Font.Color:= TColor($000000);
Font.Style:= Font.Style + [fsBold];
Brush.Color:= TColor($00FFFF);
end else
if ACol < StringGrid1.FixedCols then
begin
Font.Color:= clBlack;
Font.Style:= Font.Style + [fsBold];
Brush.Color:= clLime;
end else
if ARow mod 2 = 0 then
begin
Font.Color:= RGB(0, 0, 0);
Brush.Color:= clPurple;
end else
begin
Font.Color:= RGB(0, 0, 0);
Brush.Color:= RGB($CC, $FF, $FF);
end;
FillRect(Rect);
TextOut(Rect.Left+4,Rect.Top+4,StringGrid1.Cells[ACol,ARow]);
Font.Color:= fcl; Font.Style:= fcs; Brush.Color:= bcl;
end;
end; |