線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1959
推到 Plurk!
推到 Facebook!

如何讓TreeView.Item 反白

尚未結案
p786939
一般會員


發表:2
回覆:9
積分:2
註冊:2002-11-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-11-19 11:22:24 IP:203.74.xxx.xxx 未訂閱
請教各位高手,如何讓TreeView.Item 反白,謝謝.
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-11-19 11:34:13 IP:147.8.xxx.xxx 未訂閱
FYI, create a CustomDrawItem for the treeview.
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
    if Node.Level>0 then with Sender.Canvas do begin
        Brush.Color := clYellow;
        FillRect(Node.DisplayRect(True));
    end;
end;
p786939
一般會員


發表:2
回覆:9
積分:2
註冊:2002-11-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-11-19 11:56:23 IP:203.74.xxx.xxx 未訂閱
謝謝,如果要讓它 UnEnabled 如何設定. 
引言: FYI, create a CustomDrawItem for the treeview.
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
    if Node.Level>0 then with Sender.Canvas do begin
        Brush.Color := clYellow;
        FillRect(Node.DisplayRect(True));
    end;
end;
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-11-19 12:04:48 IP:147.8.xxx.xxx 未訂閱
引言:謝謝,如果要讓它 UnEnabled 如何設定.
What do you mean by UnEnabled?
p786939
一般會員


發表:2
回覆:9
積分:2
註冊:2002-11-12

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-11-19 12:38:04 IP:203.74.xxx.xxx 未訂閱
例如我加入十個 Item ,其中我要讓3 4 7 Item 反白Item像失效一樣,包括圖示.
引言:
引言:謝謝,如果要讓它 UnEnabled 如何設定.
What do you mean by UnEnabled?
發表人 - p786939 於 2002/11/19 12:39:32
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2002-11-19 12:47:12 IP:147.8.xxx.xxx 未訂閱
引言:例如我加入十個 Item ,其中我要讓3 4 7 Item 反白Item像失效一樣,包括圖示.
Then you need to draw the item yourself as if it is 'disabled' and remember to set DefaultDraw to false for those items.
p786939
一般會員


發表:2
回覆:9
積分:2
註冊:2002-11-12

發送簡訊給我
#7 引用回覆 回覆 發表時間:2002-11-19 12:53:16 IP:203.74.xxx.xxx 未訂閱
是否可以寫個範例示範一下,謝謝指教.
引言:
引言:例如我加入十個 Item ,其中我要讓3 4 7 Item 反白Item像失效一樣,包括圖示.
Then you need to draw the item yourself as if it is 'disabled' and remember to set DefaultDraw to false for those items.
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#8 引用回覆 回覆 發表時間:2002-11-19 14:35:00 IP:147.8.xxx.xxx 未訂閱
To draw text in disabled color:
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
    ARect: TRect;
begin
    if Node.Level>0 then with Sender.Canvas do begin
        ARect := Node.DisplayRect(True);
        Font.Color := clGrayText;
        TextRect(ARect,ARect.Left 1,ARect.Top 1,Node.Text);
    end;
end;    procedure TForm1.TreeView1Editing(Sender: TObject; Node: TTreeNode;
  var AllowEdit: Boolean);
begin
    AllowEdit := (Node.Level=0);
end;
You may need to create a 'disabled' image on the fly for drawing and it is not a trivial task. You may also want to handle the OnExpanding and OnCollapsing events to make the nodes look like really disabled.
p786939
一般會員


發表:2
回覆:9
積分:2
註冊:2002-11-12

發送簡訊給我
#9 引用回覆 回覆 發表時間:2002-11-19 15:06:37 IP:203.74.xxx.xxx 未訂閱
謝謝,我的Item 如何指定'disabled' image ,請指教.
引言: To draw text in disabled color:
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
    ARect: TRect;
begin
    if Node.Level>0 then with Sender.Canvas do begin
        ARect := Node.DisplayRect(True);
        Font.Color := clGrayText;
        TextRect(ARect,ARect.Left 1,ARect.Top 1,Node.Text);
    end;
end;    procedure TForm1.TreeView1Editing(Sender: TObject; Node: TTreeNode;
  var AllowEdit: Boolean);
begin
    AllowEdit := (Node.Level=0);
end;
You may need to create a 'disabled' image on the fly for drawing and it is not a trivial task. You may also want to handle the OnExpanding and OnCollapsing events to make the nodes look like really disabled.
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#10 引用回覆 回覆 發表時間:2002-11-19 15:25:51 IP:147.8.xxx.xxx 未訂閱
引言:謝謝,我的Item 如何指定'disabled' image ,請指教.
If you're using TImageList, try this: ImageList1.Draw(Canvas,X,Y,Index,False);
p786939
一般會員


發表:2
回覆:9
積分:2
註冊:2002-11-12

發送簡訊給我
#11 引用回覆 回覆 發表時間:2002-11-19 16:31:03 IP:203.74.xxx.xxx 未訂閱
謝謝,我不了解其中的用法,是否可以寫個範例示範一下,請指教.
引言:
引言:謝謝,我的Item 如何指定'disabled' image ,請指教.
If you're using TImageList, try this: ImageList1.Draw(Canvas,X,Y,Index,False);
系統時間:2024-05-04 17:43:36
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!