Topic: MVD font

How to replace MVD font

Destiny

Re: MVD font

Hello Destiny

If by changing MVD font you mean permanently changing the default font used by MVD, you edit the MVD XML file and replace the default font with this code:

// Open the forms.xml file in any text editor and replace
FontName = "Tahoma" FontSize = "8"
with
FontName = "Segoe UI" FontSize = "9"
// Just in case, save a copy of the forms.xml file

If you mean to allow the user to choose the font (nd save it in Register) for his project, you do this:

procedure Form1_OnShow (Sender: string; Action: string);
begin
    Form1.GridEmployees.Font := LoadFont;
end;

procedure Form1_Button5_OnClick (Sender: string; var Cancel: boolean);
var    FontDialog: TFontDialog;
begin
    FontDialog := TFontDialog.Create(Form1);
    FontDialog.Font := Form1.GridEmployees.Font;
    if FontDialog.Execute then
    begin
        Form1.GridEmployees.Font:= FontDialog.Font;
        Form1.GridEmployees.dbUpdate;
        SaveFont(Form1.GridEmployees.Font);
    end;
end;

procedure SaveFont(Font: TFont);
var   reg: TRegistry;
begin
     reg := TRegistry.Create;
     reg.Access := KEY_ALL_ACCESS;
     reg.RootKey := HKEY_CURRENT_USER;

     if reg.OpenKey('software\YourProjectName', true) then
     begin
          Reg.WriteString('Font.Name', Font.Name);
          Reg.WriteInteger('Font.Size', Font.Size);
          Reg.WriteBool('Font.Style.fsBold', fsBold in [Font.Style]);
          Reg.WriteBool('Font.Style.fsItalic', fsItalic in [Font.Style]);
          Reg.WriteBool('Font.Style.fsUnderline', fsUnderline in [Font.Style]);
          Reg.WriteBool('Font.Style.fsStrikeOut', fsStrikeOut in [Font.Style]);
          reg.CloseKey;
     end;

     reg.Free;
end;

function LoadFont: TFont;
var   reg: TRegistry;
begin
     result := TFont.Create;
     reg := TRegistry.Create;
     reg.Access := KEY_ALL_ACCESS;
     reg.RootKey := HKEY_CURRENT_USER;

     if reg.OpenKey('software\YourProjectName', true) then
     begin
          if reg.ValueExists('Font.Name') then result.Name := Reg.ReadString('Font.Name');
          if reg.ValueExists('Font.Size') then result.Size := Reg.ReadInteger('Font.Size');

          if reg.ValueExists('Font.Style.fsBold') then
              if Reg.ReadBool('Font.Style.fsBold') then result.Style := result.Style + fsBold;
          if reg.ValueExists('Font.Style.fsItalic') then
              if Reg.ReadBool('Font.Style.fsItalic') then result.Style := result.Style + fsItalic;
          if reg.ValueExists('Font.Style.fsUnderline') then
              if Reg.ReadBool('Font.Style.fsUnderline') then result.Style := result.Style + fsUnderline;
          if reg.ValueExists('Font.Style.fsStrikeOut') then
              if Reg.ReadBool('Font.Style.fsStrikeOut') then result.Style := result.Style + fsStrikeOut;

          reg.CloseKey;
     end;

     reg.Free;
end;

Cordially
JB

Re: MVD font

Thank you Jean, it works really well.

Destiny