當前位置:編程學習大全網 - 源碼下載 - delphi stringgrid 某單元格字體顏色

delphi stringgrid 某單元格字體顏色

完整的程序源碼:

您拷貝就可以運行:

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Grids;

type

TForm1 = class(TForm)

StringGrid1: TStringGrid;

procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;

Rect: TRect; State: TGridDrawState);

procedure FormCreate(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;

Rect: TRect; State: TGridDrawState);

begin

with StringGrid1 do

if Cells[ACol,ARow] = '1233' then

begin

Canvas.Font.Color := clred; //字體顏色為紅的

Canvas.Brush.color:=clMoneyGreen; //背景為 美元綠色

Canvas.FillRect(Rect);

Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol,ARow]);

end;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

with StringGrid1 do

begin

RowCount :=5;//設置5行

ColCount :=5;//設置5列

Cells[1,2]:='1233';

Cells[2,2]:='1233';

Cells[2,4]:='1233';

end;

end;

end.

-----------------------------------------------------

關鍵是DrawCell事件,在這個事件中可以設字體名、大小、顏色、字體裝飾、cell背景畫布等

---------------------------------------------------

  • 上一篇:網絡教程源代碼
  • 下一篇:如何突出信訪抓手,提升服務水平
  • copyright 2024編程學習大全網