2

基本的に、次の Delphi 2007 コード (CustomDrawItem) があります。

procedure TForm1.ListViewCustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
 if (Item.SubItems[0] = '...') then
  ListView.Canvas.Brush.Color := clSkyBlue;
end;

私の Windows XP では、すべてが完璧に動作します。

Windows XP の場合

しかし、Windows 7では、ここに私が持っているものがあります:

Windows 7 の場合

もちろん、これらの縦の白い縞模様を埋める正しいコードは何か知りたいです。しかし、なぜこれが起こっているのか知りたいです。それはデルフィから来ていますか?ウィンドウズ7? 私のコード?

4

1 に答える 1

7

ownerdraw回避策として、プロパティをtrueに設定し、OnDrawItem代わりにイベントを使用できるため、Windows7のペイント動作のようです。

そのようです

uses
  CommCtrl;

{$R *.dfm}

procedure TForm7.ListView1DrawItem(Sender: TCustomListView; Item: TListItem;
  Rect: TRect; State: TOwnerDrawState);
var
 LIndex : integer;
 ListView :  TListView;
 LRect: TRect;
 LText: string;
begin
  ListView:=TListView(Sender);
  for LIndex := 0 to ListView.Columns.Count-1 do
  begin

    if not ListView_GetSubItemRect(ListView.Handle, Item.Index, LIndex, LVIR_BOUNDS, @LRect) then
       Continue;

    if Item.Selected and (not ListView.IsEditing) then
    begin
      ListView.Canvas.Brush.Color := clHighlight;
      ListView.Canvas.Font.Color  := clHighlightText;
    end
    else
    if (Item.SubItems[0] = '...') then
    begin
      ListView.Canvas.Brush.Color := clSkyBlue;
      ListView.Canvas.Font.Color  := ListView.Font.Color;
    end
    else
    begin
      ListView.Canvas.Brush.Color := ListView.Color;
      ListView.Canvas.Font.Color  := ListView.Font.Color;
    end;

    ListView.Canvas.FillRect(LRect);
    if LIndex = 0 then LText := Item.Caption
    else LText := Item.SubItems[LIndex-1];

    ListView.Canvas.TextRect(LRect, LRect.Left + 2, LRect.Top, LText);
  end;
end;

Windows 7

ここに画像の説明を入力してください

Windows XP

ここに画像の説明を入力してください

于 2012-11-07T20:45:00.517 に答える