Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
private void OnUserCtrlResize(object sender, EventArgs e)
{
    //set the relative size
    mGetRelativeControlSize();
    Invalidate();
    Refresh();
}


C#
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);
}



C#
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();
}
Posted
Updated 20-Jul-11 22:38pm
v2

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?
 
Share this answer
 
Comments
George Nistor 21-Jul-11 4:48am    
I have tried to move up or disable. same thing

I have also overridden: onPaintBackground
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//Don't allow the background to paint
}
I have discoverd the cause:
offScreenDC.SmoothingMode = SmoothingMode.AntiAlias;

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900