tags:

views:

966

answers:

4

A coworker is encountering an error when he tries to run a VB6 app we're working on. The error is, "480: Can't create AutoRedraw image". Microsoft's documentation says this is because "There isn't enough available memory for the AutoRedraw property to be set to True. Set the AutoRedraw property to False and perform your own redraw in the Paint event procedure or make the PictureBox control or Form object smaller..."

Making the PictureBox smaller isn't an option. I'd be glad to "...perform my own redraw in the Paint event procedure...", but I'm not sure how to go about it. Can someone show me the way?

+1  A: 

Without details this will be a simplistic answer. In general most beginning VB6 programmers use AutoRedraw=True draw in responds to some input. Fill out some data, click draw, and it appears in the picture box.

The click event in the Draw Button is linked do your drawing code. The first step is move the call to the drawing code to the paint event of the picture. The second step is to replace all calls to the drawing code with MyPictureBox.Refresh. Refresh forces the paint event of that picture box to fire.

The main problem you will have to be concerned with is that the paint event is going to be fired everytime the form needs refreshed. Like if a window covering it is moved. This means that any speed issue in your drawing code will be exposed. AutoRedraw=True takes what you drew and puts in a hidden bitmap that the PictureBox uses to display what you drew.

The Paint event will execute each step of your drawing process so you have to make sure you are as fast as possible. Depending on how dynamic your application is the worse slowdown issues will become. If you are displaying a static image then the problem isn't as bad.

RS Conley
I think in your second sentence you mean "most VB6 programmers using AutoRedraw=*False* not True?
MarkJ
I think it can be considered a subjective opinion. Using AutoRedraw=True is easier for beginning programmer while experienced programmers don't. Beginning programmers comprised most of the old users of VB6.
RS Conley
The reason it is easier for beginners because you just draw it and it stays there. A slightly more straight forward algorithm than using paint.
RS Conley
A: 

There's usually a drop-down box of events for your control in the forms code window. You need to pick the paint event:

Private Sub object_Paint()

and fill in your your code for drawing on the PictureBox.

quamrana
+1  A: 

Making the PictureBox smaller isn't an option. I'd be glad to "...perform my own redraw in the Paint event procedure...", but I'm not sure how to go about it. Can someone show me the way?

That is easy. You just implement the _Paint()-Event of your Form or PictureBox and draw.

Because you are asking, i think i should clarify what the AutoRedraw-Propeprty does. If it is set to true, you can "just draw your image" any way you want. In multiple steps. Whatever. If it needs to be redrawn, for example, because another windows was on top it, it will be magically done. The down site is, that is slow, for the drawing part.

If AutoRedraw is false, no magic will happen. The Paint()-Event will be fired and you are responsible to draw your image again. This will be much faster, if your window is not "invalidated" (e.g. "covered") often. Or you are doing a lot of drawing.

Or you are running out of memory for the "magic space" ;-)

dummy
+1  A: 

If you don't mind rewriting your graphics code to use the GDI API - this could be a fairly big task - I found this thread from 2006 in the VB6 discussion group, where Mike Sutton said in answer to a similar problem:

VB's back-buffer implementation uses a Device Dependant Bitmap (DDB) to store the image data, which is quite limited in how large it can be made. On older OS' this used to be ~16mb uncompressed data size, on later OS this has been expanded but is still quite restrictive.

A workaround for this is to use a Device Independent Bitmap (DIB) and manage the GDI resources yourself, have a look at the DIB article on my site for an example of how to work with them.

I haven't tried it myself.

MarkJ