Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Listview color fondo (https://www.clubdelphi.com/foros/showthread.php?t=59437)

ANALBA 27-08-2008 10:10:03

Listview color fondo
 
Tengo un listview que cargo manualmente y en el evento CustomDrawSubItem pongo el siguiente codigo:

Código:


 if (Item.Selected) then
    Begin
    Sender.Canvas.Brush.Color := clblue;
    end;

He probado poner esto tambien:

Código:


 if (Item.Selected) then
    Begin
    SetBkColor(Sender.Canvas.Handle, clblue);
    end;

Obteniendo el mismo resultado, en los dos casos pone el fondo azul en el texto de cada subitem, pero no pone toda la linea azul, como cuando seleccionas una en automatico, alguien sabe que me falta o que estoy haciendo mal.

Gracias y un saludo

duilioisola 27-08-2008 11:18:48

Creo que debería ser así:

Código Delphi [-]
if (Item.Selected) then
    Begin
    Item.Canvas.Brush.Color := clblue;
    end;

Según el Help de Delphi:

Cita:

TCustomListView.OnCustomDrawSubItem
Occurs when a subitem must be rendered in an owner-draw list view.

type TLVCustomDrawSubItemEvent = procedure(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean) of object;
property OnCustomDrawSubItem: TLVCustomDrawSubItemEvent

Description

Write code in an OnCustomDrawSubItem handler to draw to the subitems that appear in additional columns to the right of each item when ViewStyle is vsReport. Use the list view’s Canvas property as a drawing surface. Unlike the OnDrawItem event, the list view receives this event even if the OwnerDraw property is False.

The Sender Parameter specifies the list view that owns the subitems. The Item parameter is the current Item being drawn. The SubItem parameter is the index of the subitem of that list item in its SubItems property. The State property indicates various attributes that can affect the way the subitem is drawn. Set DefaultDraw to False to prevent the list view from adding the subitem’s text after the event handler exits.

Note: OnCustomDrawSubItem occurs immediately prior to the rendering of each subitem. To augment the default drawing process at other stages (such as after the subitem is drawn), use the OnAdvancedCustomDrawSubItem event instead.

ANALBA 27-08-2008 11:23:38

Gracias por tu respuesta pero lo he probado tal cual me dices y el Item no tiene la propiedad Canvas lo has puesto tu de alguna otra manera.

Un saludo

duilioisola 27-08-2008 11:48:12

No, lo puse rápidamente, sin comporbarlo.

Mirando el Help de Delphi sobre TListItem encontré esta propiedad que supongo te puede servir:

Cita:

TListItem.DisplayRect
Returns the bounding rectangle of the list item.

type TDisplayCode = (drBounds, drIcon, drLabel, drSelectBounds);
function DisplayRect(Code: TDisplayCode): TRect;

Description

Use DisplayRect to get the coordinates of the list item in the client coordinates of the containing listview. The Code parameter specifies what part of the item the bounding rectangle surrounds. These are the possible values for the Code parameter.

Value Meaning

drBounds Returns the bounding rectangle of the entire list item, including the icon and label.
drIcon Returns the bounding rectangle of the icon or small icon
drLabel Returns the bounding rectangle of the item text
drSelectBounds Returns the union of the icon and label rectangles, but excludes columns in report view
Podrías escribir un rectánculo de color sobre el canvas de "Sender"


La franja horaria es GMT +2. Ahora son las 05:10:02.

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