Board index » delphi » problem with font size with form resize

problem with font size with form resize

I have two font size problems when resizing forms.

First I can't seem to change the main menu font size.  I have tried
changing the screen.menufont.size variable.  I even display the value in
a label caption and it shows that it has changed.  Put the change as the
very first thing in the application startup before any forms are
created.  The main menu font stays the same.

Second, I create forms as needed.  Some of those forms have tabcontrol
pages.  All but one of the forms change the tab font when I resize the
form.  One does not.  I have looked at every property on the form, the
tabcontrol and the tab pages and they are the same.  Even looked at the
forms as text and couldn't see any difference except names and position
data.

I set my system at 800 x 600 during development.  The forms are all 448
x 640.  The scale factor is then (screen.width / 640) for full screen or
other user definable value if they don't want full screen.  It becomes a
problem when the user has 1260 x 960 resolution and the menu font's and
the fonts on the "problem" form are not scaled.  The controls scale so
now I have very small text both on the tabs and on buttons, etc.

How do you change the main form menu font without having the user change
their system font settings and any ideas why this one form is acting
differently?

...Jim

 

Re:problem with font size with form resize


Make the following changes to modify the font of the menu:

- Set TMainMenu.OwnerDraw to True
- Set the OnMeasureItem of all TMenuItem's to:

procedure TForm1.MenuItemMeasureItem(Sender: TObject; ACanvas: TCanvas;
  var Width, Height: Integer);
var
  OldMeasureItem: TMenuMeasureItemEvent;
begin
  with Sender as TMenuItem do
  begin
    OldMeasureItem := OnMeasureItem;
    OnMeasureItem := nil;
    ACanvas.Font.Name := 'Courier New';
    TMyMenuItem(Sender).MeasureItem(ACanvas, Width, Height);
    OnMeasureItem := OldMeasureItem;
  end;
end;

- Set the OnAdvancedDrawItem of all TMenuItem's to:

procedure TForm1.MenuItemAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; State: TOwnerDrawState);
var
  OldAdvancedDrawItem: TAdvancedMenuDrawItemEvent;
begin
  with Sender as TMenuItem do
  begin
    OldAdvancedDrawItem := OnAdvancedDrawItem;
    OnAdvancedDrawItem := nil;
    ACanvas.Font.Name := 'Courier New';
    DrawMenuItem(TMenuItem(Sender), ACanvas, ARect, State);
    OnAdvancedDrawItem := OldAdvancedDrawItem;
  end;
end;

"Jim Andrews" <j...@azdogs.com> schreef in bericht
news:3B377AAA.4492BBDD@azdogs.com...

Quote
> I have two font size problems when resizing forms.

> First I can't seem to change the main menu font size.  I have tried
> changing the screen.menufont.size variable.  I even display the value in
> a label caption and it shows that it has changed.  Put the change as the
> very first thing in the application startup before any forms are
> created.  The main menu font stays the same.

> Second, I create forms as needed.  Some of those forms have tabcontrol
> pages.  All but one of the forms change the tab font when I resize the
> form.  One does not.  I have looked at every property on the form, the
> tabcontrol and the tab pages and they are the same.  Even looked at the
> forms as text and couldn't see any difference except names and position
> data.

> I set my system at 800 x 600 during development.  The forms are all 448
> x 640.  The scale factor is then (screen.width / 640) for full screen or
> other user definable value if they don't want full screen.  It becomes a
> problem when the user has 1260 x 960 resolution and the menu font's and
> the fonts on the "problem" form are not scaled.  The controls scale so
> now I have very small text both on the tabs and on buttons, etc.

> How do you change the main form menu font without having the user change
> their system font settings and any ideas why this one form is acting
> differently?

> ...Jim

Re:problem with font size with form resize


Thanks,

Seems like it should be easier.  If Delphi is getting the font information in
screen.menufont I don't understand why setting that value before the form is
created shouldn't be the same as changing the system's menu font.

Fixed the other problem by setting every control's parentfont to false.

Thanks,

...Jim

Quote
"M.H. Avegaart" wrote:
> Make the following changes to modify the font of the menu:

> - Set TMainMenu.OwnerDraw to True
> - Set the OnMeasureItem of all TMenuItem's to:

> procedure TForm1.MenuItemMeasureItem(Sender: TObject; ACanvas: TCanvas;
>   var Width, Height: Integer);
> var
>   OldMeasureItem: TMenuMeasureItemEvent;
> begin
>   with Sender as TMenuItem do
>   begin
>     OldMeasureItem := OnMeasureItem;
>     OnMeasureItem := nil;
>     ACanvas.Font.Name := 'Courier New';
>     TMyMenuItem(Sender).MeasureItem(ACanvas, Width, Height);
>     OnMeasureItem := OldMeasureItem;
>   end;
> end;

> - Set the OnAdvancedDrawItem of all TMenuItem's to:

> procedure TForm1.MenuItemAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas;
>   ARect: TRect; State: TOwnerDrawState);
> var
>   OldAdvancedDrawItem: TAdvancedMenuDrawItemEvent;
> begin
>   with Sender as TMenuItem do
>   begin
>     OldAdvancedDrawItem := OnAdvancedDrawItem;
>     OnAdvancedDrawItem := nil;
>     ACanvas.Font.Name := 'Courier New';
>     DrawMenuItem(TMenuItem(Sender), ACanvas, ARect, State);
>     OnAdvancedDrawItem := OldAdvancedDrawItem;
>   end;
> end;

> "Jim Andrews" <j...@azdogs.com> schreef in bericht
> news:3B377AAA.4492BBDD@azdogs.com...
> > I have two font size problems when resizing forms.

> > First I can't seem to change the main menu font size.  I have tried
> > changing the screen.menufont.size variable.  I even display the value in
> > a label caption and it shows that it has changed.  Put the change as the
> > very first thing in the application startup before any forms are
> > created.  The main menu font stays the same.

> > Second, I create forms as needed.  Some of those forms have tabcontrol
> > pages.  All but one of the forms change the tab font when I resize the
> > form.  One does not.  I have looked at every property on the form, the
> > tabcontrol and the tab pages and they are the same.  Even looked at the
> > forms as text and couldn't see any difference except names and position
> > data.

> > I set my system at 800 x 600 during development.  The forms are all 448
> > x 640.  The scale factor is then (screen.width / 640) for full screen or
> > other user definable value if they don't want full screen.  It becomes a
> > problem when the user has 1260 x 960 resolution and the menu font's and
> > the fonts on the "problem" form are not scaled.  The controls scale so
> > now I have very small text both on the tabs and on buttons, etc.

> > How do you change the main form menu font without having the user change
> > their system font settings and any ideas why this one form is acting
> > differently?

> > ...Jim

Other Threads