Redrawing a part of a control

H

Hugh Janus

Hi all,

I am drawing some lines on a picturebox control. In the .Paint event
of the picturebox I draw the lines of a graph. These lines are static
and never move. Now, in the same Sub I am drawing the plot of the
graph based on some changing variables in memory.

This works and when the variables change in memory I call the
Invalidate method of the picturebox to redraw the lines. This seems
wrong to me as I am drawing many lines again (the graph axis etc.) just
to refresh the line of the graph. It also gives me a flicker.

Does anyone know of a better way to eliminate the existing line on the
graph and redraw it (or to redraw an existing line if that is
possible.)

Thanks,
Hugh
 
S

Stuart Nathan

Create a bitmap
Dim bmp as BitMap(Width,Height)
Dim g as graphics = graphics.fromimage(bmp) - please check , not at regular
computer.
with g
..draw etc
..dispose()
end with
backgroundimage = bmp

now you can refresh and draw temp lines etc.
 
G

GhostInAK

Hello Hugh,

Set double buffering on (See the SetStyle method).. this will help to eliminate
the flicker. Also set all painting to be done in the WM_PAINT (same method).
Also, since the grid lines don't change (but I assume they are generated
dynamicly).. you could draw them into a bitmap that you hold in memory..
then when it's time to redraw the graph, blit the bitmap onto the canvas
and then redraw your value lines. Since this is raster stuff and not vector
there's really no way of saying.. erase this one line only and redraw it.
Even behind the scenes vector rendering is really raster.. same principles
apply there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top