graphic updates not doing what i thought
please bear with me on this question, i am still not sure if this is where my problem is but i need to clarify a few points.
i am rendering a grid to a split control panel ( panel2)
i have already overridden the onpaint call and in it i create a new graphic reference to the panel
Code:
protected override void OnPaint(PaintEventArgs e)
{
//base.OnPaint(e);
Graphics graphics = splitContainer1.Panel2.CreateGraphics();
graphics.Clear(Color.DimGray);
graphics.DrawImage(backg, 0, 0);
// backg is a bitmap of same dimensions as panel 2
}
i have also tried to use override this way
Code:
protected override void OnPaint(PaintEventArgs e)
{
//base.OnPaint(e);
// i assumed 'e' would hold the area i invalidated
e.Graphics.Clear(Color.DimGray);
e.Graphics.DrawImage(backg, 0, 0);
}
but this does not render the panel at all.( see comment in snippet)
so first question - does the Onpaint event redraw everything on the screen or just the area you have invalidated ?( in this case panel2) and can i tell by looking at the PaintEventArgs ?
i am also trying to eliminate some slight flicker when i click the panel and also if i drag a rectangle around on the panel it is very slow and jerky, which gives very noticable flickering. ( hand coded routine for drag method)
i am using :-
panel 2 mousedown ( to set start position of rectangle)
panel 2 mousemove ( to update the end position, set a dragging flag, and redraw the grid & rectangle(calls update method))
panel 2 mouseup ( to confirm the final position and redraw the grid + fill whatever area the rectangle encompassed)
the update routine redraws everything on the "backg" bitmap for rendering.
it draws the initial grid
it draws an array over the grid and populates it
and finally (if the dragging flag is set) it draws the outline of the rectangle over the grid and whatever is in it and calls this.Invalidate(); to force a redraw.
so second question - are these mouse events the correct places to do the jobs i am doing and if not where should they be placed ?
i realise this is probably very awkward to deal with without the full code but it is currently all on one form and runs to about 900 lines so i didint want to post it all.
(yes i know it should be in classes - but that is for another day)
EDIT:
i have cleared the rectangle redraw problem by adding a this.update(); immediately after this.Invalidate();
but still have terrible flickering