[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Client-window resize with the TTextMetric

Posted on 2006-05-18
4
Medium Priority
?
301 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:peterkiers
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 16706921
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
 
LVL 1

Author Comment

by:peterkiers
ID: 16706948
oeh!, I dont follow

Maybe something like this

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

Peter
0
 
LVL 28

Accepted Solution

by:
2266180 earned 2000 total points
ID: 16706996
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
 
LVL 1

Author Comment

by:peterkiers
ID: 16707031
Thank you for the explenation. Now i understand.

Peter
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month19 days, 6 hours left to enroll

834 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