Changing font size in firemonkey

I have a TStringGrid in Firemonkey (Delphi), and want to change the font size.

I would like to do it at design time, but runtime would be OK, too.

As simple solution like
StringGrid.Font.Size := 20;

Open in new window

doesn't compile
GrahamDLovellAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThommyCommented:
You can do it as follows...

 
var
  aCol, aRow: Integer;
  aCellCtrl: TStyledControl;


for aCol := 0 to StringGrid1.ColumnCount - 1 do  begin
    for aRow := 0 to StringGrid1.RowCount - 1 do  begin
      aCellCtrl := TColumnAccess( StringGrid1.Columns[ aCol ] ).CellControlByRow( aRow );
      if ( aCellCtrl is TTextCell ) then  begin
        TTextCell( aCellCtrl ).StyledSettings := [];
        TTextCell( aCellCtrl ).FontColor := claBlue;
        TTextCell( aCellCtrl ).Font.Family := 'Times New Roman';
        TTextCell( aCellCtrl ).Font.Style := [ TFontStyle.fsBold ];
        TTextCell( aCellCtrl ).Font.Size := 12;
      end;
    end;
  end;
end;

Open in new window

GrahamDLovellAuthor Commented:
I can see an easy front-end solution is not available.

I have tried your code in XE6, and added a couple of lines into the type section to get it to compile:
  TColumnAccess = class( TColumn )
  end;

Open in new window


I must be doing something wrong, as the following (sample) code makes no difference to the font size:

  
var
i,j: integer;
CellCtrl: TStyledControl;
~
  sgNewWords.RowCount := 6;
  for I := 0 to 5 do
    for j := 0 to sgNewWords.ColumnCount-1 do
  begin
    CellCtrl := TColumnAccess(sgNewWords.Columns[j]).CellControlByRow(i);
    if (CellCtrl is TTextCell) then
    begin
      TTextCell(CellCtrl).StyledSettings := [];
      TTextCell(CellCtrl).Font.Family := 'Times New Roman';
      TTextCell(CellCtrl).Font.Style := [ TFontStyle.fsBold ];
      TTextCell(CellCtrl).Font.Size := 20;
    end;
  end;

Open in new window


I tried this with the real row count at runtime, but it didn't work there, so I moved it into FormCreate, with a dummy number of rows, as a test. It didn't work there also.
ThommyCommented:
I'm working with XE7. What is your Version?

In XE7 you can set font size for the whole StringGrid at design or run time by StringGrid1.TextSettings.Font.Size=...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

GrahamDLovellAuthor Commented:
Thanks, that is exactly what I would like to do.

XE6 - it is also available here.

I have tried making changes at design time & while it didn't do what I wanted, it is a start. I will have another look tomorrow (Australian time).
GrahamDLovellAuthor Commented:
All fixed now. I think that the extra step required, after using TextSettings feature that you suggested, was to turn off Styled Settings.

It was also surprising that, to get the required definition for Hebrew vowels, I had to go to 30 points, at least in the Windows32 implementation.

Another thing that I found was that you can indirectly change the font size via the Scale property on TStringGrid. However, Font seems the better way.
ThommyCommented:
OK, you're right!

Unfortunately I have forgotten to tell you to set TStringGrid.StyledSettings.Size to False for proper use of TTextSettings

Sorry, but I have StyledSettings turned off by default and therefore I didn't think of that...
GrahamDLovellAuthor Commented:
Lots of flexibility in FireMonkey, but a few differences from VCL that take a bit of learning.
Thanks for your help. I am much further advanced than when I started.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.