AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

TListView.OnDrawItem

Ein Thema von WojTec · begonnen am 15. Nov 2010 · letzter Beitrag vom 17. Nov 2010
Antwort Antwort
Namenloser

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

AW: TListView.OnDrawItem

  Alt 16. Nov 2010, 09: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
 
#2

Re: TListView.OnDrawItem

  Alt 16. Nov 2010, 10: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
 
#3

AW: TListView.OnDrawItem

  Alt 16. Nov 2010, 12: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
 
#4

Re: TListView.OnDrawItem

  Alt 16. Nov 2010, 16: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
 
#5

AW: TListView.OnDrawItem

  Alt 16. Nov 2010, 16: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 16:47 Uhr)
  Mit Zitat antworten Zitat
WojTec

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

Re: TListView.OnDrawItem

  Alt 16. Nov 2010, 18: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
 
#7

AW: TListView.OnDrawItem

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

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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 14:53 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz