Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.11.07;
Скачать: CL | DM;

Вниз

StringGrid   Найти похожие ветки 

 
Bee ©   (2004-10-23 22:17) [0]

Добрый вечер!
Имеется такой код для закраски строки StringGrid:

procedure TResultForm.SGNewDrawCell(Sender: TObject; ACol,
 ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
SGNew.Canvas.Brush.Color := clSilver;
Rect.Left := stlb;
Rect.Right := stlb;
Rect.Top := 1;
Rect.Bottom := n;
SGNew.Canvas.FillRect(Rect);
end;


Подскажите, что неверно или чего не хватает, потому что строка не закрашивается. Заранее спасибо!<


 
Anatoly Podgoretsky ©   (2004-10-23 22:45) [1]

Left-right=0


 
Defunct ©   (2004-10-23 22:46) [2]

неверно то, что вы при прорисовке каждой ячейки закрашиваете строку...

надо сделать например так:

procedure TForm1.DrawCell(Sender: TObject; ACol, ARow: Integer;
 Rect: TRect; State: TGridDrawState);
begin
 With Sender as TStringGrid Do
 If ARow = Row Then
 Begin
   Canvas.Brush.Color := clSilver;
   Canvas.TextRect(Rect, 2,2, Cells[ACol, ARow]);
 End;
end;


еще скорее всего вам понадобится перерисовка ячеек по каким-то другим событиям, например, при изменении позиции скрола, изменении номера закрашиваемой строчки и т.п. Ее можно сделать так:

Procedure TForm1.RedrawCell(DG: TStringGrid; ACol, ARow: Integer);
Var State : TGridDrawState;
   Rect  : TRect;
Begin
 Rect := DG.CellRect(ACol, ARow);
 If (Rect.Top>0) And (Rect.Bottom - Rect.Top > 1) Then
 If (Rect.Left>0) And (Rect.Right - Rect.Left > 1) Then
 DrawCell( DG, ACol, ARow, DG.CellRect(ACol, ARow), State );
End;


 
Кириешки ©   (2004-10-23 23:23) [3]

Свой  StringGrid я закрашивал так :

CollectionDiscList = StringGrid.


procedure TDisc.CollectionDiscListDrawCell(Sender: TObject; ACol,
 ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
DoubleBuffered := True;
CollectionDiscList.Perform(EM_LIMITTEXT, 999999999, 0);

if Settings.CheckListBox1.Checked[6] then
BEGIN
if (gdFocused in State) then
begin
  CollectionDiscList.Canvas.Font.Color := clLime;
  CollectionDiscList.Canvas.Font.Style := [fsBold];
  CollectionDiscList.Canvas.Brush.Color := clBlack;
end
else
BEGIN
   if ACol = 0 then
    if not (CollectionDiscList.Cells[ACol,ARow] = "")
       then
        begin
        CollectionDiscList.Canvas.Font.Color := clBlack;
        CollectionDiscList.Canvas.Brush.color := $00FEEADA;
       end else
        CollectionDiscList.canvas.brush.Color := clwhite;

if ACol = 1 then
     if not (CollectionDiscList.Cells[ACol,ARow] = "")
       then
       begin
        CollectionDiscList.Canvas.Font.Color := clBlack;
        CollectionDiscList.Canvas.Brush.color := $00C6FFF8;
       end
       else
       CollectionDiscList.canvas.brush.Color := clwhite;

if ACol = 2 then
     if not (CollectionDiscList.Cells[ACol,ARow] = "")
       then
       begin
        CollectionDiscList.Canvas.Font.Color := clBlack;
        CollectionDiscList.Canvas.Brush.color := $00EAFFEA;
       end
       else
       CollectionDiscList.canvas.brush.Color := clwhite;

if ACol = 3 then
 if not (CollectionDiscList.Cells[ACol,ARow] = "")
   then
   begin
    CollectionDiscList.Canvas.Font.Color := clBlack;
    CollectionDiscList.Canvas.Brush.color := $00E1E1FF;
    end
  else
    CollectionDiscList.canvas.brush.Color := clwhite;

if ACol = 4 then
 if not (CollectionDiscList.Cells[ACol,ARow] = "")
   then
   begin
    CollectionDiscList.Canvas.Font.Color := clMaroon;
    CollectionDiscList.Canvas.Brush.color :=  $00E1E1FF;
   end
   else CollectionDiscList.canvas.brush.Color := clwhite;
end;

if ARow>0 then
 begin
   CollectionDiscList.canvas.fillRect(Rect);
   CollectionDiscList.canvas.TextOut(Rect.Left,Rect.Top,CollectionDiscList.Cells[ACol,ARow]);
 end;
END;
end;


Все закрашивается и прекрастно работает.


 
Плохиш ©   (2004-10-23 23:33) [4]


> Bee ©   (23.10.04 22:17)

Может всё-таки справку для начала почитать на предмет что такое Rect и для чего он нужен?


 
Bee ©   (2004-10-24 20:47) [5]

Огромное спасибо за помощь! :) В особенности Defunct за доступный и точный ответ, я поняла свою ошибку.



Страницы: 1 вся ветка

Текущий архив: 2004.11.07;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.046 c
8-1091714055
VaKU
2004-08-05 17:54
2004.11.07
Перемотка в DSPack


8-1091816507
parovoZZ
2004-08-06 22:21
2004.11.07
DirectInput and DirectX9


1-1098644589
S-Lok
2004-10-24 23:03
2004.11.07
Использование dll в html-файле


1-1098423661
denis24
2004-10-22 09:41
2004.11.07
разбивка строки на слова


14-1097998754
Megabyte
2004-10-17 11:39
2004.11.07
Непонятки с базой