如何改变treeView选中节点的背景色(50分)

  • 主题发起人 主题发起人 ZS99241
  • 开始时间 开始时间
Z

ZS99241

Unregistered / Unconfirmed
GUEST, unregistred user!
要实现的是整行的背景色都改变而不只是文字部份,图标和图标前的空隙也要改变的,就像QQ好友中鼠标移上去时整行的背景色都改变那种效果
 
procedure TCustomDrawForm.TVCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode;
State: TCustomDrawState;
var DefaultDraw: Boolean);
var
NodeRect: TRect;
begin
with TV.Canvasdo
begin
//If DefaultDraw it is true, any of the node's font properties can be
//changed. Note also that when DefaultDraw = True, Windows draws the
//buttons and ignores our font background colors, using instead the
//TreeView's Color property.
if cdsSelected in State then
begin
Font.Assign(SelectedFontDialog.Font);
Brush.Color := SelBkgColorDialog.Color;
end;
DefaultDraw := FDefaultDrawItem;
//DefaultDraw = False means you have to handle all the item drawing yourself,
//including the buttons, lines, images, and text.
if not DefaultDraw then

begin
//draw the selection rect.
if cdsSelected in State then
begin
NodeRect := Node.DisplayRect(True);
FillRect(NodeRect);
end;

NodeRect := Node.DisplayRect(False);
if None1.Checked then

//no bitmap, so paint in the background color.
begin
Brush.Color := BkgColorDialog.Color;
Brush.Style := FBrushStyle;
FillRect(NodeRect)
end
else
//don't paint over the background bitmap.
Brush.Style := bsClear;
NodeRect.Left := NodeRect.Left + (Node.Level * TV.Indent);
//NodeRect.Left now represents the left-most portion of the expand button
DrawButton(NodeRect, Node);
NodeRect.Left := NodeRect.Left + TV.Indent + FButtonSize;
//NodeRect.Left is now the leftmost portion of the image.
DrawImage(NodeRect, Node.ImageIndex);
NodeRect.Left := NodeRect.Left + ImageList.Width;
//Now we are finally in a position to draw the text.
TextOut(NodeRect.Left, NodeRect.Top, Node.Text);
end;
end;
end;
 
后退
顶部