如何在不选择所有节点的情况下禁用TreeView控件? [英] How to disable a TreeView control without selecting all nodes?
问题描述
我不知道这是错误还是其他原因,但是如果我尝试禁用 TTreeView
控件,则所有节点都将被选中(显示为灰色)...只是在不更改选择的情况下禁用此控件的输入?当然,并没有真正选择节点,只是在视觉上选择了节点,但这很烦人.
I don't know if this is a bug or something, but if I try to disable a TTreeView
control, all the nodes become selected (grayed out)... Can anything be done to just disable the input for this control without changing the selection ? Of course, the node are not really selected, they are just visually selected, but this is annoying.
推荐答案
这就是未应用主题时禁用控件的外观.您可以在几乎不干预项目图纸的情况下对其进行修改:
That's how the disabled control looks like when no theme is applied. You can modify it with little intervention to item drawing:
procedure TForm1.TreeView1AdvancedCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
var PaintImages, DefaultDraw: Boolean);
begin
if (not TreeView1.Enabled) and
(GetWindowTheme(TreeView1.Handle) = 0) and (Stage = cdPrePaint) then begin
TreeView1.Canvas.Brush.Color := clWindow; // or TreeView1.Color
TreeView1.Canvas.Font.Color := clGrayText;
end;
end;
不幸的是, State
从未包含'cdsDisabled'或'cdsGrayed'(我没有研究过),因此代码测试了是否启用了树视图.
Unfortunately the State
never includes 'cdsDisabled' or 'cdsGrayed' (which I didn't investigate), so the code tests if the treeview is enabled or not.
这篇关于如何在不选择所有节点的情况下禁用TreeView控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!