fontdialog 里有系统所有可用的字体以及字体所对应的大小尺寸,我想把字体名和对应大小分别显示在两个combobox里用来控制编辑界面显示, 因为不想每次设置的时候都要打开fontdialog.  字体名已经可以取到,但不知道字体所对应大小如何取得到。 还有象宋体五号字体该如何设置,(不是用fontdialog来设置,fontdialog设置好的font属性直接赋值给别的控件的font属性我知道)

解决方案 »

  1.   

    看下FontDialog.Execute的代码,里面应该有你想找的答案
      

  2.   

    首先,获得相应的属性值  if FontDialog1.Execute then
      begin
        cFontName := FontDialog1.Font.Name;
        cFontStyle:= FontStyleToString(FontDialog1.Font);
        cFontColor := FontDialog1.Font.Color;
        cFontSize := FontDialog1.Font.Size;
      end;然后自己添加到指定的combobox里即可。
    这里唯一需要特殊处理的就是style,不过也不难。给你个参考。function FontStyleToString(Font: TFont):string;
    var
      sStyle: string;
    begin
      with Font do
      begin
        sStyle := '';    if (fsBold in Style) then
          sStyle := sStyle + csfsBold;    if (fsItalic in Style) then
          sStyle := sStyle + csfsItalic;    if (fsUnderline in Style) then
          sStyle := sStyle + csfsUnderline;    if (fsStrikeOut in Style) then
          sStyle := sStyle + csfsStrikeout;    if ((Length(sStyle) > 0) and ('|' = sStyle[1])) then
          sStyle := Copy(sStyle, 2, Length(sStyle) - 1);    Result := Format('"%s", %d, [%s]',[name, Size, sStyle]);
        if bIncludeColor then
          Result := Result + Format(', [%s]',[ColorToString(Color)]);
      end;
    end;