问题
I'm getting issues drawing using OnAfterItemPaint event when horizontal scrolling is performed.
Basically what I want to achieve is the merging of selected cells effect, say for example 1 text for column 1 & 2, another text for column 3 & 4, etc... So far VT doesn't have any support for column merging, so I have to manually draw it.
Is there a workaround or another event that I should use instead?
Using: Delphi 7 + VirtualTreeview 4.8.5
Event source:
begin
TargetCanvas.TextOut(ItemRect.Left+ VT1.OffsetX, ItemRect.Top,
'1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF');
end;
Before scroll:
alt text http://a.imagehost.org/0869/screen1.gif
After scroll (Scroll Right, then Scroll Left):
alt text http://a.imagehost.org/0645/screen2.gif
回答1:
It's difficult to say what you want to achieve, but seeing that you have a long text that spans multiple columns I'm not sure you use the proper event - usually you want text to be truncated if it's too long for its column.
Anyway, the best thing is to read section 5.2 "Paint cycles and stages" in the VirtualTreeView.pdf documentation file, and find the proper event to be used for what you want to paint. For OnAfterItemPaint
it states:
The after item paint stage is used to add node specific stuff like frames and the like which concern all columns of that node and is called once per node.
so I guess it's probably not the one you want to use.
Edit:
OK, if you're going for the merging of cells you only need to remove the addition of VT1.OffsetX
(and add VT1.TextMargin
instead) to get the correct behaviour. This assumes of course you want to start the text output in the first (index 0) column, otherwise you have to calculate the horizontal text position from the column widths.
But from the description of the paint stages I still would rather use the BeforeItemPaint
event and set the CustomDraw
var parameter to True
to skip any default painting.
回答2:
Have you tried this:
TreeOptions.AutoOptions := TreeOptions.AutoOptions + [toAutoSpanColumns];
It pretty much does what you need. They only issue might be that you can't specify which columns it is enabled for. You can probably get around this by limitation by setting the celltext to a whitespace for the columns you don't want to span into.
来源:https://stackoverflow.com/questions/1516082/delphi-virtualtreeview-onafteritempaint-issue-when-scrolling