Client-window resize with the TTextMetric

Hi,

I'm making a 3270-component and I use a TTextMetric in the Paint-event.
When i change the size of the font in de Constructor-procedure the
TTextMetric gets larger. Is it possible to get the client-window resize with it.

procedure TDSP3333.Paint;
var
  TxMetric: TTextMetric ;
begin
  with Canvas do
      begin
        Brush.Style := bsSolid ;
        Brush.Color := fColorBlack ;
        FillRect(ClipRect) ;
    end ;
  Canvas.Font.Size := fFontSize ;
  Canvas.Font.Name := fFontName ;
  GetTextMetrics(Canvas.Handle,TxMetric) ;
  fFontWidthPix := TxMetric.tmAveCharWidth ;
  fFontHeightPix := TxMetric.tmHeight ;
  showbuf;
end;

procedure TDSP3333.ShowBuf;
var    i, j: integer ;
begin
    for i := 1 to fSCRROWS do
    for j := 1 to fSCRCOLS do
      DispCell(j,i,false) ;
    DrawCursor(fCsrCol,fCsrRow) ;    //drawcursor
  ShowStatus ;                               //draw statusbar
end;

Peter
LVL 1
peterkiersAsked:
Who is Participating?
 
2266180Connect With a Mentor Commented:
well .. it's a simple ... "aspect ratio" if you want.

think of 2 rectangles: abcd and mnpq

a------b
|.......|
d------c

m-----------n
|..............|
|..............|
|..............|
q-----------p

those are the 2 canvases, abcd for the component and mnpq for the form.
I might not have a good picture of your compnent/application but this is how I see it at the moment.

now, when you modify the height/width of the font in the component, you want everything to resize according to that, right?

I will leave the form out and explain it for the component only. (forget my previous comment :) )
so before resize you have:
component height/witdth (CH/CW)
font height/width (FH/FW)

let's assume that CH/FH = a (ch float div fh)
and CW/FW = b
now, in order to keep aspect ration, both a and b must remain constant through any of resize or font change.
so that means that AFTER resize, a and b will be the same
so, if you modify the font, you will have

ACH/AFH = a (A from after, c from component and h/w from height/width/ hope you are following this :) )
ACW/AFW = b

getting back, you can write this as:
ACH/AFH = CH/FH
ACW/AFW = CW/FW

now. if you modify the font, that means that AFH and AFW are known (they are the new sizes of the font). if you modify the component, then ACH and ACW are known (new sizes of the component)

so for height,
ACH/AFH = CH/FH
and in first case you will have ACH = AFH*CH/FH
and in second case AFH = ACH*FH/CH

simple elementary math :)

you will probably understand it better if you draw everything ;) (that is how I done it when I started doing such stuff)

the same aspect ration algorithm applies for the form as well (only if you want)
you will have to save a and b though in the component ;)
0
 
2266180Commented:
well ... right now all I can think of is a simple way:
get the textmetrics of the component canvas (CC ) and the form canvas (FC)
it is matematically true (for your case with resize) that:
CC.height/CC.metric.fontheight = FC.height/FC.metric.fontheight
same for width
then, you know the cc.height/width, the cc.metric.fontheight/width and the fc.metric.fontheight/width so you calculate the dc.height/width from there :)
0
 
peterkiersAuthor Commented:
oeh!, I dont follow

Maybe something like this

procedure TDSP3270.Resize;
begin
  inherited;
  ClientHeight := .....
  ClientWidth := .....
end;

Peter
0
 
peterkiersAuthor Commented:
Thank you for the explenation. Now i understand.

Peter
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.