如何扩展控件的绘制。 [英] How to extend painting of a control.

查看:59
本文介绍了如何扩展控件的绘制。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在轨迹栏控件上添加刻度标签。每个刻度在它下面都有一个标签。

因此我执行以下操作:





Hi,
I want to add tick labels to a trackbar control. Each tick has a label underneath it.
Therefore I do the following :


public DateTimeTrackBar()
{
    :
    SetStyle(ControlStyles.UserPaint  | ControlStyles.ResizeRedraw, true);
}







protected override void OnPaintBackground(PaintEventArgs e)
{
    base.OnPaintBackground(e);

    if (ShowLabels)
        DrawLabels(e);
}





标签图纸工作正常,但原始轨迹栏消失了。

如何保留原始轨迹栏并使用我的标签绘图代码进行扩展?



tia



The label drawing works fine, except that the original trackbar disappears.
How can i keep the original trackbar drawing and extend it with my label drawing code ?

tia

推荐答案

而不是 OnPaintBackground (其目的不同),覆盖 OnPaint

Control.OnPaint Method(PaintEventArgs)( System.Windows.Forms) [ ^ ]。



或者,您可以处理相应的事件 System.Windows.Drawing.Control.Paint 。但是你不需要它,因为你正在编写派生类,所以压倒不是问题。顺便说一句,如果你覆盖这个方法,不要处理这个事件(你可以做到这两个,但通常它是无效的)并且不希望用户处理这个事件,不要调用 base.Paint



-SA
Instead of OnPaintBackground (its purpose is different), override OnPaint:
Control.OnPaint Method (PaintEventArgs) (System.Windows.Forms)[^].

Alternatively, you can handle the corresponding event System.Windows.Drawing.Control.Paint. But you don't need it because you are writing derived class anyway, so overriding is not a problem. By the way, if you override the method, don't handle this event (you could do it both, but usually it's poinless) and don't want the users to handle this event, don't call base.Paint.

—SA


这篇关于如何扩展控件的绘制。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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