全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1545
推到 Plurk!
推到 Facebook!

ListView 使用 DoubleBuffered 造成顯示不正常的問題

缺席
blue
中階會員


發表:169
回覆:136
積分:81
註冊:2002-04-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2012-12-26 08:26:11 IP:124.219.xxx.xxx 訂閱
Hi,各位先進大家好:
小弟因需自遠端將縮圖調回顯示在ListView中,
在OnDrawCustomItem中加入了一個重疊的圖上去(例如一個分享的符號),
至此顯示都很正常,
但,為了避免閃爍,
在ListView中加了DoubluBuffered,
就造成了該分享的符號無法正常顯示了(多半沒顯示,有時滑鼠移到該項目才顯示,移走又不顯示了),
不知各位先進是否遇到相同問題?
謝謝!
附上簡易測試代碼如下,
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ComCtrls, Vcl.StdCtrls, Vcl.ImgList,
Vcl.ExtCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
Button1: TButton;
ImageList1: TImageList;
Image3: TImage;
procedure Button1Click(Sender: TObject);
procedure ListView1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
Item: TListItem;
begin
for i := 0 to 10 do begin
Item := ListView1.Items.Add;
Item.Caption := 'File' IntToStr(i);
Item.ImageIndex := i; // 註: ListView.SmallImages 指向一個已載入照片的 ImageList
end;
end;
procedure TForm1.ListView1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
var
CurnNode: TTreeNode;
Domain, CurnPath: TFileName;
X,Y: Integer;
Rect: TRect;
Cvs: TCanvas;
begin
if (Item.Caption = 'File5') or (Item.Caption = 'File8') then exit;
try
Cvs := TCanvas.Create;
Cvs.Handle := GetDC(Item.Handle);
X := Item.Position.X;
Y := Item.Position.Y;
Rect.Left := X 32 - 32;
Rect.Top := Y 32 - 10;
Rect.Width := 32;
Rect.Height := 10;
Cvs.StretchDraw(Rect, Image3.Picture.Bitmap);
finally
Cvs.Free;
end;
end;
end.

blue
中階會員


發表:169
回覆:136
積分:81
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2012-12-26 13:33:30 IP:124.219.xxx.xxx 訂閱
Hi,
已解決,小弟的解決方法是將DoubleBuffered的設置改為只有在載入縮圖的區塊中,
謝謝!


===================引 用 blue 文 章===================
Hi,各位先進大家好:
小弟因需自遠端將縮圖調回顯示在ListView中,
在OnDrawCustomItem中加入了一個重疊的圖上去(例如一個分享的符號),
至此顯示都很正常,
但,為了避免閃爍,
在ListView中加了DoubluBuffered,
就造成了該分享的符號無法正常顯示了(多半沒顯示,有時滑鼠移到該項目才顯示,移走又不顯示了),
不知各位先進是否遇到相同問題?
謝謝!
附上簡易測試代碼如下,
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ComCtrls, Vcl.StdCtrls, Vcl.ImgList,
Vcl.ExtCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
Button1: TButton;
ImageList1: TImageList;
Image3: TImage;
procedure Button1Click(Sender: TObject);
procedure ListView1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
Item: TListItem;
begin
for i := 0 to 10 do begin
Item := ListView1.Items.Add;
Item.Caption := 'File' IntToStr(i);
Item.ImageIndex := i; // 註: ListView.SmallImages 指向一個已載入照片的 ImageList
end;
end;
procedure TForm1.ListView1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
var
CurnNode: TTreeNode;
Domain, CurnPath: TFileName;
X,Y: Integer;
Rect: TRect;
Cvs: TCanvas;
begin
if (Item.Caption = 'File5') or (Item.Caption = 'File8') then exit;
try
Cvs := TCanvas.Create;
Cvs.Handle := GetDC(Item.Handle);
X := Item.Position.X;
Y := Item.Position.Y;
Rect.Left := X 32 - 32;
Rect.Top := Y 32 - 10;
Rect.Width := 32;
Rect.Height := 10;
Cvs.StretchDraw(Rect, Image3.Picture.Bitmap);
finally
Cvs.Free;
end;
end;
end.

系統時間:2024-04-25 20:32:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!