簡體   English   中英

StringGrid Delphi XE2的Cell是如何着色的?

[英]How colored the Cell of StringGrid Delphi XE2?

我從Delphi開始。 我遇到了TStringGrid和Colored the Cell的問題。 我選擇BackGround時使用此代碼進行顏色處理:

procedure TForm_Matrix.MatrizGeneralDrawCell(Sender: TObject;
  ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
  ACol:=MatrizGeneral.Col;
  ARow:=MatrizGeneral.Row;
  begin
    if (RBAlto.Checked = True) then // Nivel de color ROJO - ALTO
      MatrizGeneral.Canvas.Brush.Color :=clRed;
      MatrizGeneral.Canvas.FillRect(Rect);
    if (RBMedio.Checked = True) then
      MatrizGeneral.Canvas.Brush.Color :=clYellow;
      MatrizGeneral.Canvas.FillRect(Rect);
    if (RBBajo.Checked = True) then
      MatrizGeneral.Canvas.Brush.Color :=clLime;
      MatrizGeneral.Canvas.FillRect(Rect);
  end;
end;

它的工作,但當我嘗試改變顏色改變選擇的細胞,和第一個細胞idk為什么。

  1. 當我選擇3個紅色的單元格時。 (工作正常) 在此輸入圖像描述

  2. 改變另一個細胞的顏色,改變第一個細胞TT 在此輸入圖像描述

    http://i.stack.imgur.com/umG0r.png http://i.stack.imgur.com/1o93C.png

救命!!!

如果要僅為選定的單元格着色,則必須檢查傳入的State參數,並且僅在選擇State時繪制。

此外,您正在該例程中繪制單元格3x。 只需輸入MatrizGeneral.Canvas.FillRect(Rect); 一旦結束,每個IF塊都不需要它。

我使用這個rutine為用放射性組選擇的細胞着色:

if MatrizGeneral.Cells[ACol,ARow] <> '' then begin
case StrToInt(MatrizGeneral.Cells[ACol,ARow]) of
  0: BGColor := clRed;
  1: BGColor := clYellow;
  2: BGColor := clLime;
else
  BGColor := clWhite;
end;
with MatrizGeneral do begin
  Canvas.Brush.Color := BGColor;
  Canvas.FillRect(Rect);

  if (gdFocused in State) then
    Canvas.Font.Color := clWhite
  else
    Canvas.Font.Color := clBlack;
end;

結束;

效果很好!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM