Font Color on a StringGrid with firemonkey

I‘m changing the background color based on the data but it makes my text hard to read so I need to change the font color (to white if I have a darker color) but I can‘t find a way to do it, I‘m using Delphi XE8.

if not (isSelected) then
  begin
    case StrToInt((Sender as TStringGrid).Cells[0, Row]) of
      0:
      begin
        //TTextCell(CellCtrl).StyledSettings := [];
        TTextCell(CellCtrl).FontColor := Cores[3 - auxCor - 1];
        RowColor.Color := Cores[auxCor-1];
      end;
      1:
      begin
        //TTextCell(CellCtrl).StyledSettings := [];
        TTextCell(CellCtrl).FontColor := TAlphaColors.Black;
        RowColor.Color := TAlphaColors.Red;
      end;
      2:
      begin
        //TTextCell(CellCtrl).StyledSettings := [];
        TTextCell(CellCtrl).FontColor := TAlphaColors.Black;
        RowColor.Color := TAlphaColors.Yellow;
      end;
      3:
      begin
        //TTextCell(CellCtrl).StyledSettings := [];
        TTextCell(CellCtrl).FontColor := TAlphaColors.Black;
        RowColor.Color := TAlphaColors.LightGreen;
      end;
    end;
  end;

  Canvas.FillRect(Bounds, 0, 0, [], 1, RowColor);

  TGrid(Sender).DefaultDrawColumnCell(Canvas, Column, Bounds, Row,
    Value, State);
  (Sender as TStringGrid).Selected := SelectedRow;

the TTextCell portion doesn‘t do anything (I have an else with a similar case where I set a color to Green so I need the text to be white (if white ends up being hard to read I‘ll try some other colors).

Cores is an array with Black and White TAlphaColors

delphi fonts firemonkey stringgrid


shareimprove this question

edited Oct 6 ‘15 at 17:33

RRUZ

118k12271413

asked Oct 1 ‘15 at 11:55

Ricardo Alvares Pereira Junior

819

 

Got it:

had to change the gridcolor right before calling the DefaultDrawColumnCell method:

procedure TFrmMainMaximized.StringGridDrawColumnCell(
  Sender: TObject; const Canvas: TCanvas; const Column: TColumn;
  const Bounds: TRectF; const Row: Integer; const Value: TValue;
  const State: TGridDrawStates);
var
  RowColor : TBrush;
  isSelected : boolean;
  FontColor : Integer;
  SelectedRow : Integer;
begin

  RowColor := Tbrush.Create(TBrushKind.Solid, TAlphaColors.Alpha);

  isSelected := ((Sender as TStringGrid).Selected = Row) and
                ((Sender as TStringGrid).ColumnIndex = Column.Index);
  SelectedRow := (Sender as TStringGrid).Selected;

  if not (isSelected) then
  begin
    case StrToInt((Sender as TStringGrid).Cells[0, Row]) of
      0:
      begin
        FontColor := Cores[3 - auxCor - 1];
        RowColor.Color := Cores[auxCor-1];
      end;
      1:
      begin
        FontColor := TAlphaColors.Black;
        RowColor.Color := TAlphaColors.Red;
      end;
      2:
      begin
        FontColor := TAlphaColors.Black;
        RowColor.Color := TAlphaColors.Yellow;
      end;
      3:
      begin
        FontColor := TAlphaColors.Black;
        RowColor.Color := TAlphaColors.LightGreen;
      end;
    end;
  end
  else
  begin
    case StrToInt((Sender as TStringGrid).Cells[0, Row]) of
      0:
      begin
        FontColor := Cores[auxCor - 1];
        RowColor.Color := Cores[3 - auxCor-1];
      end;
      1:
      begin
        FontColor := TAlphaColors.Black;
        RowColor.Color := TAlphaColors.Pink;
      end;
      2:
      begin
        FontColor := TAlphaColors.Black;
        RowColor.Color := TAlphaColors.LightYellow;
      end;
      3:
      begin
        FontColor := TAlphaColors.White;
        RowColor.Color := TAlphaColors.Green;
      end;
    end;
  end;

  Canvas.FillRect(Bounds, 0, 0, [], 1, RowColor);

  TGridAccess((Sender as TStringGrid)).GetTextSettingsControl.ResultingTextSettings.FontColor := FontColor;

  TGrid(Sender).DefaultDrawColumnCell(Canvas, Column, Bounds, Row,
    Value, State);
  inherited;
end;

the TextSettingControl property from the grid is protected so I had to make an access Class with this function:

function TGridAccess.GetTextSettingsControl: TTextCell;
begin
  result := inherited TextSettingsControl;
end;

https://stackoverflow.com/questions/32887019/font-color-on-a-stringgrid-with-firemonkey

时间: 2024-10-10 04:52:50

Font Color on a StringGrid with firemonkey的相关文章

Freecms商业版标题颜色问题,font color=’000000’

原文地址:http://javaz.cn/site/javaz/site_study/info/2015/35418.html 项目地址:http://www.freeteam.cn/ 如果在模板中使用信息标题,有以下三种格式. info.title  信息的原标题,不做任何处理,直接显示信息的标题 info.shorttitle  信息的短标题,会根据你的标签,如infoList标题中的titleLen属性,对info.title进行截取,如titleLen设置为10,那么info.short

输出字体颜色 "<li><font color=red>" + ......+ "</font>"

<title>4-15</title> <script language="javascript"> <!-- var students = new Array( "杨宗楠", "杨玉婷", "李莉" ); for( index in students ) { if( students[index] != "杨宗楠" ) //不是"杨宗楠"就输出

(一)关于SWT程序的基本架构,如何使用控件以及使用Image,Font,Color等图形资源内容

import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.

字体和颜色 Font Color 基础笔记

private void SelectFontAndColor_Load(object sender, EventArgs e) {//窗体加载的时候,初始化字体 //返回所有的字体 FontFamily[] fontF = FontFamily.Families; //下拉单显示的是name comboBox1.DisplayMember = "Name"; //绑定数据 comboBox1.DataSource = fontF; //设置当前下拉单的字体有两种方法 //1..这里可

&lt;font color=&quot;#db000a&quot;&gt;代表风采|&lt;/font&gt;李元敏:打造村民引以为豪的新&quot;盖买&quot;s

乌克兰的国家政治选择似乎注定了内部斗争的愈演愈烈.特别是在大国中,没有哪个国家有我们这样高的速度.指尖处神经丰富,针扎时较疼痛,一般选择指尖两侧作为采血点.是不是要把你的城市发展的目的重点解决人进来的问题,公共服务问题.两年前的春天,百盛入驻济南,基本没有做什么宣传,静悄悄地开了业.他昨天说,的确有很多父母开始为考研的学生张罗相亲了,尤其是女生,父母似乎更着急.今年,该项目已经推广到9个省10个县实施.截至2013年第三季度末,中国海外房地产投资同比上涨25%.记者刘卓毅老人遇险:电梯犯病邻居上

UIAlertController custom font, size, color

本文转载至 http://stackoverflow.com/questions/26460706/uialertcontroller-custom-font-size-color up vote2down votefavorite 3 I am using new UIAlertController for showing alerts. I have this code: // nil titles break alert interface on iOS 8.0, so we'll be

如何将 Font Awesome 转成 PNG 图标 详细教程 含源代码

最近因为项目上需要用到这个字体图标,但是它里面的许多也不能完全满足项目需要,因此就考虑将这个图标导出,然后自己再添加一些其他图标使用 搜索了些解决方案,如:http://www.oschina.net/translate/how-to-convert-font-awesome-to-png-icons,但是上面的步骤过于简单,一个新手完全不会使用,比如Python自己就一点都没接触过,因此自己走了许多弯路. 本文一方面记录以便以后自己再次使用,最重要的是将我自己的每个步骤详细的展现给有需要的大家

Html学习(二)font 加粗 斜体 下划线标签学习

代码: <font size="10">6</font> <font size="2">6</font> <font color="red" size="10">红色 字号10的6</font> <font face="黑体" size="20" >这是黑色的字</font> <b>

change the color of a disabled TEdit?

Author: P. Below Category: VCL {Question:How can I change the color of a disabled (Edit1.Enabled := false;) control?I do not want the normal grey color. Answer:Two options: 1) place the control on a panel and disable the panel instead of the control.