蓝 蓝天 Unregistered / Unconfirmed GUEST, unregistred user! 2000-02-29 #1 我用 DBGrid 做了一个成绩单,想把90分以上用红色显示,不及格用兰色显示, 但是 DBGrid1.Columns.Font.Color 属性只能设置整列的字体颜色,我 应该怎样做呢 ?
英 英国病人 Unregistered / Unconfirmed GUEST, unregistred user! 2000-02-29 #2 响应DBGrid1的DrawColumnCell事件: procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if Table1.FieldByName('分数').AsInteger > 90 then DBGrid1.Canvas.Font.Color := clRed; DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;
响应DBGrid1的DrawColumnCell事件: procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if Table1.FieldByName('分数').AsInteger > 90 then DBGrid1.Canvas.Font.Color := clRed; DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;
英 英国病人 Unregistered / Unconfirmed GUEST, unregistred user! 2000-02-29 #3 响应DBGrid1的DrawColumnCell事件: procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if Table1.FieldByName('分数').AsInteger > 90 then DBGrid1.Canvas.Font.Color := clRed; if Table1.FieldByName('分数').AsInteger < 60 then DBGrid1.Canvas.Font.Color := clBlue; DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;
响应DBGrid1的DrawColumnCell事件: procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if Table1.FieldByName('分数').AsInteger > 90 then DBGrid1.Canvas.Font.Color := clRed; if Table1.FieldByName('分数').AsInteger < 60 then DBGrid1.Canvas.Font.Color := clBlue; DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;
S shenjian Unregistered / Unconfirmed GUEST, unregistred user! 2000-02-29 #4 英国病人的应该就是答案。注意 DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); 不可少
X xWolf Unregistered / Unconfirmed GUEST, unregistred user! 2000-02-29 #5 DBGrid1.Canvas.Font.Color := clBlue; // FIELDNAME为成绩字段名 if (Column.Field.FieldName = FIELDNAME) and (Column.Field.AsFloat >= 90) then begin DBGrid1.Canvas.Font.Color := clRed; end; DBGrid1.Canvas.FillRect(Rect); DBGrid1.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Column.Field.AsString);
DBGrid1.Canvas.Font.Color := clBlue; // FIELDNAME为成绩字段名 if (Column.Field.FieldName = FIELDNAME) and (Column.Field.AsFloat >= 90) then begin DBGrid1.Canvas.Font.Color := clRed; end; DBGrid1.Canvas.FillRect(Rect); DBGrid1.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Column.Field.AsString);