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.
// 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
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.
