2010. június 24., csütörtök

Draw text in the node of a TTreeView in bold style


Problem/Question/Abstract:

I would like to write the text of each node in a TTreeview by including the text in the standard way with a trailing number written in bold and color blue.

Answer:

This is a code snippet of a descendant of a TTreeView that handles the bold state of a treenode:

function TTreeView1.GetNodeBoldState(Node: TTreeNode): boolean;
var
  TVItem: TTVItem;
begin
  result := false;
  if not Assigned(Node) then
    exit;
  with TVItem do
  begin
    mask := TVIF_STATE;
    hitem := Node.ItemId;
    result := TreeView_GetItem(Node.Handle, TVItem) and ((State and TVIS_BOLD) <> 0);
  end;
end;

procedure TTreeView1.SetNodeBoldState(Node: TTreeNode; value: boolean);
var
  TVItem: TTVItem;
begin
  if not Assigned(Node) then
    exit;
  fillchar(TVItem, sizeof(TVItem), 0);
  with TVItem do
  begin
    mask := TVIF_STATE or TVIF_HANDLE;
    hitem := Node.ItemId;
    StateMask := TVIS_BOLD;
    if value then
      State := TVIS_BOLD;
    TreeView_SetItem(Node.Handle, TVItem);
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése