2015-04-29 7 views
6

Ich mag würde den Text von einem Knoten von VirtualStringTree nach Suchkriterien wie beispielsweise von unten markieren:TVirtualStringTree Highlight Ergebnis der Suche

enter image description here

Jeder Vorschlag bitte?

+3

Mir ist keine eingebaute Funktion bekannt, um Text hervorzuheben. Sie müssen wahrscheinlich Owner-Draw-Methoden verwenden - OnBeforeCellPaint, OnPaintText usw. – smooty86

+0

Benötigen Sie Unterstützung für mehrzeilige Knoten mit umschlossenem Text? – TLama

+0

Jetzt, da Sie über umschlossenen Text erwähnen, werde ich nach etwas Hilfe suchen. In diesem Moment habe ich keine Ahnung, wie ich damit umgehen soll, zumindest von wo aus ich anfangen soll ... Jedenfalls wenn du Links oder Infos hast, die mir helfen können, ist willkommen. Vielen Dank im Voraus! – REALSOFO

Antwort

1

Dank TLama Antwort (How to underline or highlight a part of node caption) stelle ich ein wenig den Code ein, um den Text auch in der Mitte zu markieren.

procedure Tform_main.vt_mainDrawText(Sender: TBaseVirtualTree; 
    TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; 
    const Text: string; const CellRect: TRect; var DefaultDraw: Boolean); 
var 
    BackMode, position: Integer; 
begin 
    // if the just rendered node's Text contain the text written in a TEdit control 
    // called Edit, then... 
    position:= Pos(AnsiLowerCase(edit_search.Text), AnsiLowerCase(text)); 
    if position > 0 then 
    begin 
    // store the current background mode; we need to use Windows API here because the 
    // VT internally uses it (so the TCanvas object gets out of sync with the DC) 
    BackMode := GetBkMode(TargetCanvas.Handle); 
    // setup the color and draw the rectangle in a width of the matching text 
    TargetCanvas.Brush.Color := clYellow; 
    TargetCanvas.FillRect(Rect(
     CellRect.Left + TargetCanvas.TextWidth(Copy(Text, 1, position-1)), 
     CellRect.Top + 3, 
     CellRect.Left + TargetCanvas.TextWidth(Copy(Text, 1, position-1)) + TargetCanvas.TextWidth(Copy(Text, position, Length(edit_search.Text))), 
     CellRect.Bottom - 3) 
    ); 
    // restore the original background mode (as it likely was modified by setting the 
    // brush color) 
    SetBkMode(TargetCanvas.Handle, BackMode); 
    end; 
end; 

Beste Wünsche zu TLama!