{"id":118,"date":"2007-05-12T14:32:51","date_gmt":"2007-05-12T12:32:51","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/small-fonts-large-fonts-3\/"},"modified":"2007-05-12T14:32:52","modified_gmt":"2007-05-12T12:32:52","slug":"small-fonts-large-fonts-3","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/small-fonts-large-fonts-3\/","title":{"rendered":"Small Fonts \/ Large Fonts (3)"},"content":{"rendered":"<p><em>><br \/>\n> Hello,<br \/>\n><br \/>\n> I made an application that looks fine when windows is using small fonts, but<br \/>\n> if the user is using large fonts, the form looks bad.<br \/>\n><br \/>\n> What can I do to solve this problem??..<br \/>\n> I think that maybe the solution is to detect if the user is using large<br \/>\n> fonts and resize the form and the controls, but I am not sure. that this is<br \/>\n> the correct way to do it..<br \/>\n><br \/>\n> Thanks,<br \/>\n<\/em><br \/>\nHere&#8217;s an earlier post on this popular subject&#8230;<br \/>\n<!--more--><br \/>\n==================================================<\/p>\n<p>Hi there for who is interested in this subject!<\/p>\n<p>There were discussions here about problems caused when app is<br \/>\ndeveloped on one system settings and then executed on other.<br \/>\nI played a little bit with this and found out a satisfactory solution<br \/>\nfor me&#8230;<\/p>\n<p>I designed my app in small fonts (96 DPI) with Scaled = false and<br \/>\ntried to execute it on large fonts (120 DPI) and results were perfect<br \/>\nfor what I put on my forms. I thought someone might benefit from what<br \/>\nI have done. <\/p>\n<p>Special care was taken for alignments and anchoring&#8230; please try it<br \/>\nyourself. Just call the FixDPI function below after form creation.<\/p>\n<p>yours,<br \/>\ntomi.<\/p>\n<p>[code lang=&#8221;delphi&#8221;]procedure FixDPI(f: TForm; DesignDPI: integer);<\/p>\n<p>(*<br \/>\n        Small\/Large system font solution<br \/>\n        Have a TForm&#8217;s properties Scaled and AutoScroll set to false<br \/>\n        and after creating your form call this procedure like:<br \/>\n                FixDPI (TForm1, 96) \/\/ If you designed in small fonts<\/p>\n<p>        Author: Tomislav Kardas, Zagreb, Croatia, Europe<br \/>\n        Platform: Delphi 4 C\/S<br \/>\n*)<\/p>\n<p>var<br \/>\n  ScaleM, ScaleD: integer;<\/p>\n<p>  function Scale(x: longint): longint;<br \/>\n  begin<br \/>\n    result := (x*ScaleM + ScaleD div 2) div ScaleD;<br \/>\n  end;<\/p>\n<p>  procedure FixControl(c: TControl);<br \/>\n  var<br \/>\n    x: integer;<br \/>\n    p: TWinControl;<br \/>\n    fixheight: boolean;<br \/>\n  begin<br \/>\n    p := c.Parent;<br \/>\n    if c.Align <> alNone then begin<br \/>\n      \/\/ Fixing width<br \/>\n      if ((c.Align = alLeft) and (akRight in c.Anchors)) or<br \/>\n         ((c.Align = alRight) and (akLeft in c.Anchors)) then<br \/>\n        c.Width := p.ClientWidth &#8211; Scale(p.ClientWidth &#8211; c.Width)<br \/>\n      else if (c.Align = alLeft) or (c.Align = alRight) then<br \/>\n        c.Width := Scale(c.Width);<br \/>\n      \/\/ Fixing height<br \/>\n      if ((c.Align = alTop) and (akBottom in c.Anchors)) or<br \/>\n         ((c.Align = alBottom) and (akTop in c.Anchors)) then<br \/>\n        c.Height := p.ClientHeight &#8211; Scale(p.ClientHeight &#8211; c.Height)<br \/>\n      else if (c.Align = alTop) or (c.Align = alBottom) then<br \/>\n        c.Height := Scale(c.Height);<br \/>\n      end<br \/>\n    else begin<br \/>\n      \/\/ Fixing width<br \/>\n      x := p.ClientWidth &#8211; c.Width &#8211; c.Left;<br \/>\n      if akLeft in c.Anchors then begin<br \/>\n        c.Left := Scale(c.Left);<br \/>\n      if akRight in c.Anchors then<br \/>\n        c.Width := p.ClientWidth &#8211; c.Left &#8211; Scale(x)<br \/>\n      else<br \/>\n        c.Width := Scale(c.Width);<br \/>\n      end<br \/>\n    else if akRight in c.Anchors then begin<br \/>\n      c.Width := Scale(c.Width);<br \/>\n      c.Left := p.ClientWidth &#8211; c.Width &#8211; Scale(x);<br \/>\n      end<br \/>\n    else begin<br \/>\n      c.Left := Scale(c.Left);<br \/>\n      c.Width := Scale(c.Width);<br \/>\n      end;<br \/>\n    \/\/ Fixing height<br \/>\n    fixheight := true;<br \/>\n    if (c is TCustomEdit) and not (c is TCustomMemo) then<br \/>\n      fixheight := false;<br \/>\n    x := p.ClientHeight &#8211; c.Height &#8211; c.Top;<br \/>\n    if akTop in c.Anchors then begin<br \/>\n      c.Top := Scale(c.Top);<br \/>\n      if fixheight then begin<br \/>\n        if akBottom in c.Anchors then<br \/>\n          c.Height:= p.ClientHeight &#8211; c.Top &#8211; Scale(x)<br \/>\n        else<br \/>\n          c.Height:= Scale(c.Height);<\/p>\n<p>        end;<br \/>\n      end<br \/>\n    else if akBottom in c.Anchors then begin<br \/>\n      if fixheight then<br \/>\n        c.Height := Scale(c.Height);<br \/>\n      c.Top := p.ClientHeight &#8211; c.Height &#8211; Scale(x);<br \/>\n      end<br \/>\n    else begin<br \/>\n      c.Top := Scale(c.Top);<br \/>\n      if fixheight then<br \/>\n        c.Height := Scale(c.Height);<br \/>\n      end;<br \/>\n    end;<br \/>\n  end;<\/p>\n<p>  procedure FixControls(c: TWinControl);<br \/>\n  var<br \/>\n    i: integer;<br \/>\n  begin<br \/>\n    for i := 0 to c.ControlCount &#8211; 1 do<br \/>\n      if c.Controls[i].Owner = f then begin<br \/>\n        FixControl(c.Controls[i]);<br \/>\n        if c.Controls[i] is TWinControl then<br \/>\n          FixControls(TWinControl(c.Controls[i]));<br \/>\n        end;<br \/>\n  end;<\/p>\n<p>begin<br \/>\n  if DesignDPI <> Screen.PixelsPerInch then begin<br \/>\n    ScaleM := Screen.PixelsPerInch;<br \/>\n    ScaleD := DesignDPI;<br \/>\n    f.ClientWidth := Scale(f.ClientWidth);<br \/>\n    f.ClientHeight := Scale(f.ClientHeight);<br \/>\n    FixControls(f);<br \/>\n    end;<br \/>\nend;<br \/>\n[\/code]<\/p>\n<p>[tags]Delphi, Forms[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>> > Hello, > > I made an application that looks fine when windows is using small fonts, but > if the user&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[75,100],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-1U","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/118"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}