通过 API 函数更改字体过程。

解决方案 »

  1.   

    就是往控件上写字啊,你可以看看Windows API方面编程的书
      

  2.   

    procedure TmwCustomEdit.SetFont(const Value: TFont);
    var
      DC: HDC;
      Save: THandle;
      Metrics: TTextMetric;//米制,单位
      AveCW, MaxCW: Integer;
    begin
      DC := GetDC(0);//取得本窗体字体控制柄
      Save := SelectObject(DC, Value.Handle);
      GetTextMetrics(DC, Metrics);取得当前字体的单位。
      SelectObject(DC, Save);
      ReleaseDC(0, DC);
      with Metrics do
      begin
        AveCW := tmAveCharWidth;//平均字符宽度
        MaxCW := tmMaxCharWidth;//最大字符宽度
      end;
      case AveCW = MaxCW of
        True: inherited Font := Value;
        False:
          begin
            with fFontDummy do
            begin
              Color := Value.Color;//下面就不说
              Pitch := fpFixed;
              Size := Value.Size;
              Style := Value.Style;
            end;
            inherited Font := fFontDummy;
          end;
      end;
    end;
    procedure TmwCustomEdit.FontChanged(Sender: TObject);
    var
      DC: HDC;
      Save: THandle;
      Metrics: TTextMetric;
    begin
      DC := GetDC(0);
      Save := SelectObject(DC, Font.Handle);
      GetTextMetrics(DC, Metrics);
      SelectObject(DC, Save);
      ReleaseDC(0, DC);
      with Metrics do
      begin
        fCharWidth := tmAveCharWidth;
        fTextHeight := tmHeight + tmExternalLeading;
        if PaintLock = 0 then Invalidate;
      end;
    end;