PRocedure SetComCtrlStyle(WinCtrl: TWinControl; Value: Integer; UseStyle: Boolean); var Style: Integer; begin if WinCtrl.HandleAllocated then begin Style := GetWindowLong(WinCtrl.Handle, GWL_STYLE); ifnot UseStyle then Style := Style andnot Value else Style := Style or Value; SetWindowLong(WinCtrl.Handle, GWL_STYLE, Style); end; end;
然后 在 OnCreate 調(diào)用:
SetComCtrlStyle(TreeView1, TVS_CHECKBOXES, True);
或者干脆簡單點,一句話完事:
SetWindowLong(TreeView1.Handle, GWL_STYLE, GetWindowLong(TreeView1.Handle, GWL_STYLE) or $00000100);