2012-03-26 6 views
3

Lazarus v0.9.30 (32 비트 컴파일러)을 사용하고 있습니다. TStringGrid의 TColumnTitle 개체와 관련된 개체에 저장된 힌트 텍스트를 표시하는 데 사용하는 다음 코드가 있습니다.TStringGrid 셀과 관련된 힌트 텍스트의 글꼴 크기를 변경하는 방법

procedure TTmMainForm.TmApplicationPropertiesShowHint 
    (
    var HintStr: string; 
    var CanShow: boolean; 
    var HintInfo: THintInfo 
    ); 
var 
    aGrid  : TStringGrid; 
    aColumnTitle : TTmColumnTitle; 
    aRow   : integer; 
    aColumn  : integer; 
begin 
    aRow := 0; 
    aColumn := 0; 

    HintInfo.HintMaxWidth := 200; 
    HintInfo.HideTimeout := 10000; 
    HintInfo.HintColor := $00D7FBFA; 

    //Get a pointer to the current grid. 
    aGrid := TStringGrid(HintInfo.HintControl); 

    //Find out what cell the mouse is pointing at. 
    aGrid.MouseToCell(HintInfo.CursorPos.X, HintInfo.CursorPos.Y, aColumn, aRow); 

    if ((aRow = 0) and (aColumn < aGrid.ColCount)) then 
    begin 
     //Get the object associated with the column title. 
     aColumnTitle := TTmColumnTitle(aGrid.Objects[aColumn, aRow]); 

     //Define where the hint window will be displayed. 
     HintInfo.CursorRect := aGrid.CellRect(aColumn, aRow); 

     //Display the hint. 
     HintStr := Trim(aColumnTitle.stHint); 
    end; {if} 
end; 

나는 HintInfo 개체에 액세스 할 수 있으며이 개체를 사용하여 힌트 텍스트의 글꼴 크기를 변경하려고합니다. HintInfo 객체는 HintInfo.HintControl.Font에 대한 액세스를 제공하지만이 메서드를 사용하면 기본 TStringGrid의 모든 셀 텍스트 글꼴을 변경합니다. HintInfo 개체는 Hintinfo.HintWindowClass.Font에 대한 액세스도 제공하지만 Font.Size에 액세스 할 수 없습니다. 힌트의 글꼴 크기를 수정하는 방법이 있습니까?

답변

4

이 목적을 위해 만들어진 TScreen.HintFont 속성이 있지만 그 게터에서 나에게 잘못된 것 같습니다. 이 시점에서 내가 말할 수있는 한 가지 예상대로 작동하지 않습니다. 힌트 창 인스턴스에 액세스 할 수 없으므로 수행 할 수있는 최선의 작업은 하위 클래스 공통 힌트 창 클래스입니다.

다음 예제에서는 현재 사용되지 않은 HintInfo.HintData을 통해 크기 값을 전달하여 글꼴 크기를 지정할 수있는 사용자 지정 힌트 창 클래스를 만들었습니다.

uses 
    Windows, Types; 

type 
    TCustomHintWindow = class(THintWindow) 
    private 
    function CalcHintRect(MaxWidth: Integer; const AHint: string; 
     AData: Pointer): TRect; override; 
    end; 

const 
    HintBorderWidth = 2; 

implementation 

function TCustomHintWindow.CalcHintRect(MaxWidth: Integer; const AHint: string; 
    AData: Pointer): TRect; 
begin 
    if MaxWidth <= 0 then 
    MaxWidth := Screen.Width - 4 * HintBorderWidth; 
    Result := Types.Rect(0, 0, MaxWidth, Screen.Height - 4 * HintBorderWidth); 
    if AHint = '' then 
    Exit; 
    if Assigned(AData) then 
    Canvas.Font.Size := Integer(AData); 
    DrawText(Canvas.GetUpdatedHandle([csFontValid]), PChar(AHint), Length(AHint), 
    Result, DT_CALCRECT or DT_NOPREFIX or DT_WORDBREAK); 
    Inc(Result.Right, 4 * HintBorderWidth); 
    Inc(Result.Bottom, 4 * HintBorderWidth); 
end; 

procedure TForm1.ApplicationProperties1ShowHint(var HintStr: string; 
    var CanShow: Boolean; var HintInfo: THintInfo); 
begin 
    HintInfo.HintColor := $0000ECFF; 
    HintInfo.HintData := Pointer(12); 
    HintStr := 'Hi I''m just a testing hint...'; 
end; 

procedure TForm1.FormCreate(Sender: TObject); 
begin 
    HintWindowClass := TCustomHintWindow; 
end; 

여기에 어떻게 보이는지 스크린 샷입니다 같은 :

enter image description here

관련 문제