Recent

Author Topic: Difference in appearance XP, Vista, 7  (Read 6267 times)

PeterH

  • New Member
  • *
  • Posts: 31
Difference in appearance XP, Vista, 7
« on: August 23, 2010, 11:33:27 am »
When I start my application (which is compiled under Windows XP) in Windows Vista or 7 some controls are different in size.
For intance : Stringgrid heights are larger and inplace editors are slighly in other positions.

Is there some setting to prevent this from happening? Or do I have to compile two versions?

Sora-Kun

  • Full Member
  • ***
  • Posts: 162
  • I can smell your presence ...
    • Sora-Kun
Re: Difference in appearance XP, Vista, 7
« Reply #1 on: August 23, 2010, 02:03:53 pm »
Hello,
The same thing happnes to me  %)
the solution that I found is from the "Project" meni, select compiler options, then select Qt from the Graphical componant Type. Your application will not use the default windows componant, which are not the same on WindowsXP and VISTA.
This shall work, If not i have no other idea.
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.

Made in Lazarus.
Soon, in The WWW.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8764
  • Programming + Glam Metal + Tae Kwon Do = Me

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: Difference in appearance XP, Vista, 7
« Reply #3 on: August 24, 2010, 08:32:53 am »
When I start my application (which is compiled under Windows XP) in Windows Vista or 7 some controls are different in size.
For intance : Stringgrid heights are larger and inplace editors are slighly in other positions.

Is there some setting to prevent this from happening? Or do I have to compile two versions?

Windows versions after XP use a different font & font size (SegoeUI 9pt) so that could be the reason why you have that behaviour.

What I did in my case was to test for the Windows version in the code before setting the fonts. I assume the application is being run on a machine with Windows XP or earlier (< 6) & I use XP default fonts & sizes. But if the machine runs Vista or later (>= 6), I change the font & its size at Form level & since all controls inherit the parent's font, every control changes too.

Code: [Select]
 // Change the form fonts to Windows Vista default (Segoe UI 9) if the application is
  // being run on a Windows Vista machine
  {$IFDEF MSWINDOWS}
  if IsWindowsVista then
  begin
    SetVistaFonts(Self);
  end;
  {$ENDIF}

I place the code above in the Form.Create section of every form in my application.

The functions that the code snippet above rely on are as shown below
Code: [Select]
const
  VistaFont = 'Segoe UI';
  VistaContentFont = 'Calibri';
  XPContentFont = 'Verdana';
  XPFont = 'Tahoma';

.......


procedure SetVistaFonts(const AForm: TCustomForm);
begin
  if IsWindowsVista and not SameText(AForm.Font.Name, VistaFont) and (Screen.Fonts.IndexOf(VistaFont) >= 0) then
  begin
    if AForm.Font.Size = 0 then
      AForm.Font.Size := AForm.Font.Size + 9
    else
      AForm.Font.Size := AForm.Font.Size + 1;

    AForm.Font.Name := VistaFont;
  end;
end;

function IsWindowsVista: Boolean;
var
  VerInfo: TOSVersioninfo;
begin
  VerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
  GetVersionEx(VerInfo);
  Result := VerInfo.dwMajorVersion >= 6;
end;

The functions above can be in a file of their own which is added to the Uses clause of every form in your application.

This works perfectly. I've had no problems with fonts & font sizes since.  :D


« Last Edit: August 24, 2010, 10:07:20 am by JD »
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

 

TinyPortal © 2005-2018