用户控件中的小物件 [英] small artefact in an user control

查看:56
本文介绍了用户控件中的小物件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我创建了一个用户控件,打算在其中创建一些图形图表.
我戴上了固定的用户控件边框样式,并在其中绘制了要绘制的白色矩形(背景).

我的问题是,为什么有时在矩形的边缘(通常在顶部或左侧),我会看到一些随机的灰色像素.为什么调整大小后会消失?矩形从控件的左上角坐标0,0绘制.


下面的一些代码:

类CPlotGraphUserControl:UserControl

在这堂课中,我有:

Hi
I created an user control where I intend to do some grafical charts.
I put on the user control border style fixed and inside I plot a white rectangle (my background) where I intend to plot.

My question is why sometimes at the edge of the rectangle (usualy in the top or left area) I see some random grey pixels..why disapear if I do resize? The rectangle is ploted from 0,0 which is top left coordinated of the control.


some code below:

class CPlotGraphUserControl : UserControl

in this class i have:

private void OnUserCtrlResize(object sender, EventArgs e)
{
    //set the relative size
    mGetRelativeControlSize();
    Invalidate();
    Refresh();
}





protected void mInitGraphicalComponents()
{
    offScreenBmp = new Bitmap(xSizeMax, ySizeMax);
    offScreenDC = Graphics.FromImage(offScreenBmp);
    offScreenDC.SmoothingMode = SmoothingMode.AntiAlias;

    mUsedPenDrawGraphics = new Pen(Color.Black, 1);

    //white Backround
    offScreenDC.FillRectangle(backGroundBrush, 0, 0, xSizeMax, ySizeMax);
}







protected override void OnPaint(PaintEventArgs e)
{
    mGetRelativeControlSize();

    mNormalizeMxCoordinates();
    mInitGraphicalComponents();

    //do some drawind here    

    //Draw the image from the memory bitmap object
    e.Graphics.DrawImage(offScreenBmp, new Rectangle(0, 0, xSizeMax, ySizeMax), 0, 0, xSizeMax, ySizeMax, GraphicsUnit.Pixel);

    base.OnPaint(e);
    mDisposeGraphicalComponents();
}

推荐答案

由于它们是灰色的-我认为您使用的不是颜色-可能是由于EraseBackground所致.您是否尝试过:
1)卸下base.OnPaint(e);
2)将其移到您的工程图代码上方?
Since they are grey - and I assume that isn''t a color you are using - it may be due to teh EraseBackground in some way. Have you tried:
1) Removing the base.OnPaint(e);
2) Moving it above your drawing code?


我已经找到了原因:
offScreenDC.SmoothingMode = SmoothingMode.AntiAlias;

如果我在上面这一行发表评论,那么伪影就会消失.
有人注意到吗?
I have discoverd the cause:
offScreenDC.SmoothingMode = SmoothingMode.AntiAlias;

if I comment the above line the artefact dissapear.
does anyone noticed this?


这篇关于用户控件中的小物件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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