Solved

Font size of the text in a DBGrid

Posted on 2011-02-11
4
739 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:ewangoya
ewangoya 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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