问题
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.
回答1:
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;
Unfortunately the State
never includes 'cdsDisabled' or 'cdsGrayed' (which I didn't investigate), so the code tests if the treeview is enabled or not.
来源:https://stackoverflow.com/questions/59216513/how-to-disable-a-treeview-control-without-selecting-all-nodes