Solved

Font size of the text in a DBGrid

Posted on 2011-02-11
4
813 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 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