Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   TTreeView y Custom Draw de texto (https://www.clubdelphi.com/foros/showthread.php?t=59049)

lag_0 11-08-2008 12:19:41

TTreeView y Custom Draw de texto
 
Buenas,
A ver si alguien me pude ayudar.. Tengo un TTreeView y quiero que "dibuje" un texto diferente al que tiene la propiedad Text de cada node, el problema es que no encuentro como hacerlo...

he intentado esto:
Código Delphi [-]
procedure TSmartsExplorer.BTreeCustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
      Node.Text := 'Test';
end;

Pero eso me cambia el texto del nodo...
Alguien me da una idea?
Muchas gracias.

coso 11-08-2008 12:49:08

Hola, es ir jugando con la propiedad canvas. Fijate que defaultdraw lo asigno aqui, pero solo asignandolo una vez por algun otro lado ya tendrias bastante

Código Delphi [-]
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
        R : TRect;
begin
        DefaultDraw := false;
        R := Node.DisplayRect(false);
        Sender.Canvas.Brush.Color := clBtnFace;
        Sender.Canvas.FillRect(R);
        Sender.Canvas.TextOut(R.Left,R.Top,'item text = ' + Node.Text);
end;

lag_0 11-08-2008 13:02:05

Buenas,
Ante todo; Gracias por contestar.

Como dices, efectivamente, ese código funciona; El problema, es que si hago un DefaultDraw := False; Me cargo las imágenes de los nodos, las lineas de "arbol" etc. etc....

Solo quiero cambiar el texto.. y no sé me ocurre como hacerlo...
Gracias una vez más.

Edit:
He conseguido hacerlo... basandome en la ayuda de coso, pero, consigo un efecto muy "feo", yo pinto un nuevo texto sobre el nodo y cuando lo seleccionas queda solo hasta donde ocupe el texto original, y no sé puede hacer "click" en la parte que no existe sin draw...
Se os ocurre algo:
Código Delphi [-]
procedure TSmartsExplorer.BTreeAdvancedCustomDrawItem(
  Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState;
  Stage: TCustomDrawStage; var PaintImages, DefaultDraw: Boolean);
var
  R:TRect;
  TempS:string;
begin
  TempS := 'Texto para pintar';
  R := Node.DisplayRect(True);
  Sender.Canvas.FillRect(Node.DisplayRect(true));
  Sender.Canvas.TextOut(R.Left,R.Top,TempS);
end;

coso 11-08-2008 13:56:56

Hola, eso es por el Node.DisplayRect, si lo pones a true, solo te da un rectangulo con el tamaño del texto anterior.

coso 11-08-2008 14:01:35

Umm no, que relei. Echa una busqueda por el foro, porque este tema esta bastante tratado, y seguro que encuentras como arreglarlo. Saludos.

lag_0 12-08-2008 11:34:06

Pues yo seré tonto o ciego pero ni en google encuentro nada @___@

¿Me hechas una mano por favor? No consigo hacer que "redibuje" el tamaño del item claro que es casi perfecto así...

Pero si fuera perfecto mejor aún :p

coso 12-08-2008 12:12:34

Te dejo un post que parece algo relacionado : este . Tambien, usando la ayuda de delphi sobre THitTest, se encuentra esto

Cita:

Unit

Comctrls

type
THitTest = (htAbove, htBelow, htNowhere, htOnItem, htOnButton, htOnIcon, htOnIndent, htOnLabel, htOnRight, htOnStateIcon, htToLeft, htToRight);
THitTests = set of THitTest;

Description

THitTests is a set of THitTest values. THitTest can have any of the following values:

Value Means the point is

htAbove Above the client area.
htBelow Below the client area.
htNowhere Inside the control, but not on an item.
htOnItem On an item, its text, or its bitmap.
htOnButton On a button.
htOnIcon On an icon.
htOnIndent On the indented area of an item.
htOnLabel On a label.
htOnRight On the right side of an item.
htOnStateIcon On a state icon or bitmap associated with an item.
htToLeft To the left of the client area.
htToRight To the right of the client area.
creo q con una combinacion del GetHitTestInfoAt (en el mensaje anterior sale como usarlo) usando como hittest, por ejemplo, el htOnRight o el htOnIndent, deberias solucionarlo. De igual manera he buscado rapidamente. Creo que he visto bastantes variaciones del treeview, aqui en el foro, con el codigo fuente, asi que es posible que este solucionado ;) venga un saludo y suerte

coso 12-08-2008 12:14:15

A ver, por eso, si esta tarde tengo tiempo y saco un ejempo :confused::confused: saludos otra vez


La franja horaria es GMT +2. Ahora son las 18:12:33.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi