Solved

Font size of the text in a DBGrid

Posted on 2011-02-11
4
780 Views
Last Modified: 2012-05-11
Please look at the sql in the related question for more info. Basically I have made the column width to a fixed number(70). It is too small to hold the entire Ip address if each octet is 3 digits. So how can I make the text that appears in the cells smaller? I tried the following, but did not work:
procedure TDNSForm.GatewayGridDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  if Column.Field.DataSet.RecNo = 1 then
  (Sender as TDBGrid).Canvas.Font.Color := clMedGray
  else
  //(Sender as TDBGrid).Canvas.Font.Size := 2; // This line did not work either
  Column.Font.Size := 4;
  GatewayGrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
0
Comment
Question by:QurbanDurrani
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
Thommy earned 250 total points
ID: 34876601
Set DBGrid-property DefaultDrawing=false

Call DefaultDrawColumnCell in your OnDrawColumnCell event for all columns, which you don't want to change

Set Canvas.Font.Size for your desired column

You MUST call method Canvas.TextOut() to write your field text into the the cell...



TDBGrid.OnDrawColumnCell Event
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/DBGrids_TDBGrid_OnDrawColumnCell.html

TCustomDBGrid.DefaultDrawing Property
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/DBGrids_TCustomDBGrid_DefaultDrawing.html

TCanvas.TextOut Method
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Graphics_TCanvas_TextOut.html
0
 

Author Comment

by:QurbanDurrani
ID: 34877092
Thanks Thommy. I have left work. I will give your suggestion a shot when I go back to work Monday morning.
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 250 total points
ID: 34881298

Note that most fonts will not go below FontSize of 8.
If you put in a smaller value than 8, it will just be ignored

Try selecting a font that is already small then set the size to 8
eg
(Sender as TDBGrid).Canvas.Font.Name := Vrinda;
(Sender as TDBGrid).Canvas.Font.Size := 8
0
 

Author Closing Comment

by:QurbanDurrani
ID: 34889193
Thanks for your help guys.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question