AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

TListView.OnDrawItem

Ein Thema von WojTec · begonnen am 15. Nov 2010 · letzter Beitrag vom 17. Nov 2010
Antwort Antwort
Seite 2 von 3     12 3      
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.861 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: TListView.OnDrawItem

  Alt 15. Nov 2010, 21:28
Have a look on onCustomDraw
Markus Kinzler
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#12

Re: TListView.OnDrawItem

  Alt 16. Nov 2010, 10:42
I tried OnCustomDraw and OnCustomDrawItem and set in both DefaultDraw to True. And I still don't have default selection. How to use it?
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#13

AW: TListView.OnDrawItem

  Alt 16. Nov 2010, 10:50
TListview doesn't support the themed selection rectangle out of the box. You have to activate it manually by calling SetWindowTheme(Listview.Handle, 'Explorer', nil);
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#14

Re: TListView.OnDrawItem

  Alt 16. Nov 2010, 11:03
I added it to OnCreate, this is good procedere?
Still no effect OnDrawItem should be in OnCustomDrawItem? But this don't have Rect parameter. Don't have idea how to do it
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#15

AW: TListView.OnDrawItem

  Alt 16. Nov 2010, 13:43
Does it work if you don't use any owner/custom drawing code?

Btw: As you're already using clGrayText , why not use clWindowText for regular text as well? Depending on the settings, text may not always be black by default. In general, you should avoid combining environment colors with hard coded colors, because it can get ugly (e.g. black text on a black background) if someone uses different settings.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#16

Re: TListView.OnDrawItem

  Alt 16. Nov 2010, 17:07
If I don't use owner draw (in owner draw event I put my drawing code) items selection is as in all other listview components (system too). When enable owner drawing I don't have selection, though in custom draw event default draw is on.
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#17

AW: TListView.OnDrawItem

  Alt 16. Nov 2010, 17:43
You could use MSDN-Library durchsuchenDrawThemedBackground from the UxTheme api. Here's a quick example:
Delphi-Quellcode:
uses UxTheme;

TMyForm = class(TForm)
private
  Theme: hTheme;
end;

procedure TMyForm.FormCreate(Sender: TObject);
begin
  Theme := OpenThemeData(0, 'ListView');
end;

procedure TMyForm.FormDestroy(Sender: TObject);
begin
  CloseThemeData(Theme);
end;

procedure TMyForm.ListViewCustomDraw(...);
var
  StateId: Integer;
begin
  StateId := LIS_SELECTED; // LIS_SELECTEDNOTFOCUS // LIS_NORMAL
  DrawThemeBackground(
    Theme,
    ListView.Canvas.Handle,
    LVP_LISTITEM,
    StateId,
    Rect,
    nil
  );
  { Other drawing code... }
end;
But if you do this, be careful to check if Themes are available or else your program will not work on older systems.

[edit]
In order to see any difference, you have to execute the SetWindowTheme-code from above first (before you acquire the theme handle). Or you could replace 'ListView' with 'Explorer::ListView' . But the former version is preferable.
[/edit]

Geändert von Namenloser (16. Nov 2010 um 17:47 Uhr)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#18

Re: TListView.OnDrawItem

  Alt 16. Nov 2010, 19:12
Don't working, when try select item, all what is inside control is erased, so component is blank.

Maybe I'm calling in wrong order? I have: OwnerDraw is True, OnDrawItem to make grey text, OnCustom* event with DefaultDraw set to True. Now selection is don't visible, but items are with black and grey text. Then I added your first code for themes to form OnCreate - result was the same, then repleaced it with next example - control area is cleared.

  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#19

AW: TListView.OnDrawItem

  Alt 16. Nov 2010, 21:37
Maybe you should post your source code along with a screenshot.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#20

Re: TListView.OnDrawItem

  Alt 17. Nov 2010, 10:33
Form:
Delphi-Quellcode:
object Form20: TForm20
  Left = 0
  Top = 0
  Caption = 'Form20'
  ClientHeight = 202
  ClientWidth = 331
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object lvRecentFiles: TListView
    Left = 8
    Top = 8
    Width = 225
    Height = 175
    Columns = <
      item
        Caption = 'Recent files'
        Width = 221
      end>
    ColumnClick = False
    DoubleBuffered = True
    Groups = <
      item
        Header = 'Recent files'
        GroupID = 0
        State = [lgsNormal]
        HeaderAlign = taLeftJustify
        FooterAlign = taLeftJustify
        TitleImage = -1
        ExtendedImage = -1
      end>
    Items.ItemData = {
      03C60000000300000000000000FFFFFFFFFFFFFFFF0000000000000000000000
      001F43003A005C00570069006E0064006F00770073005C007300790073007400
      65006D00330032005C005300680065006C006C00330032002E0064006C006C00
      00000000FFFFFFFFFFFFFFFF0000000000000000000000000B43003A005C0062
      006F006F0074002E0069006E00690000000000FFFFFFFFFFFFFFFF0000000000
      000000000000001258003A005C006E006F006E00650078006900730074006500
      6E0074002E00640061007400}

    OwnerDraw = True
    GroupView = True
    ReadOnly = True
    RowSelect = True
    ParentDoubleBuffered = False
    ShowColumnHeaders = False
    TabOrder = 0
    ViewStyle = vsReport
    OnCustomDraw = lvRecentFilesCustomDraw
    OnCustomDrawItem = lvRecentFilesCustomDrawItem
    OnDrawItem = lvRecentFilesDrawItem
  end
end
Source:
Delphi-Quellcode:
unit Unit20;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, UxTheme;

type
  TForm20 = class(TForm)
    lvRecentFiles: TListView;
    procedure lvRecentFilesDrawItem(Sender: TCustomListView; Item: TListItem;
      Rect: TRect; State: TOwnerDrawState);
    procedure lvRecentFilesCustomDraw(Sender: TCustomListView;
      const ARect: TRect; var DefaultDraw: Boolean);
    procedure lvRecentFilesCustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    Theme: hTheme;
  public
    { Public declarations }
  end;

var
  Form20: TForm20;

implementation

{$R *.dfm}

procedure TForm20.FormCreate(Sender: TObject);
begin
  SetWindowTheme(lvRecentFiles.Handle, 'Explorer', nil);
  Theme := OpenThemeData(0, 'ListView');
end;

procedure TForm20.FormDestroy(Sender: TObject);
begin
  CloseThemeData(Theme);
end;

procedure TForm20.lvRecentFilesCustomDraw(Sender: TCustomListView;
  const ARect: TRect; var DefaultDraw: Boolean);
//var
// StateId: Integer;
begin
// StateId := LIS_SELECTED; // LIS_SELECTEDNOTFOCUS // LIS_NORMAL
// DrawThemeBackground(
// Theme,
// lvRecentFiles.Canvas.Handle,
// LVP_LISTITEM,
// StateId,
// ARect,
// nil
// );
  DefaultDraw := True;
end;

procedure TForm20.lvRecentFilesCustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  DefaultDraw := True;
end;

procedure TForm20.lvRecentFilesDrawItem(Sender: TCustomListView;
  Item: TListItem; Rect: TRect; State: TOwnerDrawState);
var
  R: TRect;
  S: string;
begin
  S := Item.Caption;

  with lvRecentFiles, lvRecentFiles.Canvas do
  begin
    if FileExists(S) then
      Font.Color := clWindowText
    else
      Font.Color := clGrayText
    ;

    R := Classes.Rect(Rect.Left + 6, Rect.Top + 3, Rect.Right, Rect.Bottom - 2);
    TextRect(R, S, [tfEndEllipsis]);
  end;
end;

end.
Group header has selection, items not

Screen attached.
Miniaturansicht angehängter Grafiken
listview.jpg  
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 3     12 3      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:44 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz