Solved

Font size of the text in a DBGrid

Posted on 2011-02-11
4
705 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now