Question

How can I use my own custom buttons (images) to replace the default [-]/[+] buttons in the VST?
I want to use arrows instead (enter image description here, enter image description here), but also to support RTL bidi mode (enter image description here, enter image description here).

edit: I am aware of the bsTriangle style (ButtonStyle). It does not respect RTL. I want to use my own custom images.

Was it helpful?

Solution

Aren't those images usually in Windows Vista and Windows 7? The tree control should get them automatically on those systems when you have themes enabled.

The easy way to get something close to that is to just set the ButtonStyle property to bsTriangle. It won't be exactly the images shown in the question, though. The "minus" arrow will point straight down instead of diagonally, and the "plus" arrow will be solid instead of an outline.

You can provide your own bitmap. Change the VT_XPBUTTONMINUS and VT_XPBUTTONPLUS resources to whatever images you want, and set the ButtonFillMode property to fmShaded.

I see no facility for changing the image based on the bi-di mode, though. You can create a descendant class that overrides PaintNodeButton, and then paint whatever you want. Copy the placement code from the parent class.

OTHER TIPS

IIRC you get it by including toUseExplorerTheme in PaintOptions. However this also changes the selection look (to the better IMNSHO) and probably more.

For example if I drop a TVirtualStringTree on a form and add the following event handlers:

procedure TForm1.FormCreate(Sender: TObject);
begin
  VT.RootNodeCount := 10;
  VT.TreeOptions.PaintOptions := VT.TreeOptions.PaintOptions + [toUseExplorerTheme];
  VT.OnInitNode := VTInitNode;
  VT.OnInitChildren := VTInitChildren;
end;

procedure TForm1.VTInitChildren(Sender: TBaseVirtualTree;
  Node: PVirtualNode; var ChildCount: Cardinal);
begin
  ChildCount := 3;
end;

procedure TForm1.VTInitNode(Sender: TBaseVirtualTree;
  ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
begin
  Include(InitialStates, ivsHasChildren);
end;

I get screenshot with triangular markers

Edit: Unfortunately, setting Form1.BiDiMode to bdRightToLeft yields screenshot with wrong triangular markers on my German Windows 7. I don't know if this works better on Arabic or Hebrew systems.

See the ButtonStyle property. Not sure does it respect the RTL bidi mode thought.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top