滚动时出现Delphi VirtualTreeview.OnAfterItemPaint问题? [英] Delphi VirtualTreeview.OnAfterItemPaint issue when scrolling?

查看:93
本文介绍了滚动时出现Delphi VirtualTreeview.OnAfterItemPaint问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行水平滚动时,使用 OnAfterItemPaint 事件进行绘制时出现问题.

I'm getting issues drawing using OnAfterItemPaint event when horizontal scrolling is performed.

基本上,我要实现的是所选单元格效果的合并,例如第1列和第1列的1个文本2,第3列和第3列的另一文本4,等等...到目前为止,VT对列合并没有任何支持,因此我必须手动绘制它.

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?

使用:Delphi 7 + VirtualTreeview 4.8.5

Using: Delphi 7 + VirtualTreeview 4.8.5

事件源:

begin
  TargetCanvas.TextOut(ItemRect.Left+ VT1.OffsetX, ItemRect.Top,
    '1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF');
end;

滚动前:

替代文本http://a.imagehost.org/0869/screen1.gif

滚动后(向右滚动,然后向左滚动):

After scroll (Scroll Right, then Scroll Left):

替代文本http://a.imagehost.org/0645/screen2.gif

推荐答案

很难说出您要实现的目标,但是看到您的文本跨越了多列,我不确定您是否使用了正确的事件-通常,如果文本的列长度太长,则希望将其截断.

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.

无论如何,最好的办法是阅读 VirtualTreeView.pdf 文档文件,然后找到要用于绘画的适当事件.对于OnAfterItemPaint,它指出:

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.

好的,如果您要合并单元格,则只需删除添加的VT1.OffsetX(并添加VT1.TextMargin)即可获得正确的行为.当然,这假设您要在第一列(索引0)中开始文本输出,否则必须从列宽计算水平文本位置.

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.

但是从绘画阶段的描述来看,我还是希望使用BeforeItemPaint事件并将CustomDraw var参数设置为True来跳过任何默认绘画.

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.

这篇关于滚动时出现Delphi VirtualTreeview.OnAfterItemPaint问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆