Client-window resize with the TTextMetric

Posted on 2006-05-18
Last Modified: 2010-04-05

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;
  TxMetric: TTextMetric ;
  with Canvas do
        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 ;

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

Question by:peterkiers
    LVL 28

    Expert Comment

    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 :)
    LVL 1

    Author Comment

    oeh!, I dont follow

    Maybe something like this

    procedure TDSP3270.Resize;
      ClientHeight := .....
      ClientWidth := .....

    LVL 28

    Accepted Solution

    well .. it's a simple ... "aspect ratio" if you want.

    think of 2 rectangles: abcd and mnpq



    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:

    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,
    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 ;)
    LVL 1

    Author Comment

    Thank you for the explenation. Now i understand.


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    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…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    729 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

    21 Experts available now in Live!

    Get 1:1 Help Now