当前位置:编程文档 >> DELPHI >> Delphi中为TreeView添加单选和复选框
首页

Delphi中为TreeView添加单选和复选框

所属类别:DELPHI
推荐指数:★★★☆
文档人气:185
本周人气:2
发布日期:2008-4-17

下面的代码可以让Treeview前面显示CheckBox.


const
TVS_CHECKBOXES = $00000100;

procedure SetComCtrlStyle(WinCtrl: TWinControl; Value: Integer; UseStyle: Boolean);
var
Style: Integer;
begin
  if WinCtrl.HandleAllocated then
  begin
    Style := GetWindowLong(WinCtrl.Handle, GWL_STYLE);
    if not UseStyle then
    Style := Style and not Value
    else Style := Style or Value;
    SetWindowLong(WinCtrl.Handle, GWL_STYLE, Style);
  end;
end;

 


然后 在 OnCreate 调用:


SetComCtrlStyle(TreeView1, TVS_CHECKBOXES, True);
 

 

或者干脆简单点,一句话完事:


SetWindowLong(TreeView1.Handle, GWL_STYLE, GetWindowLong(TreeView1.Handle, GWL_STYLE) or $00000100);

文档说明:

     

相关文档


读取评论列表……