# Paint problem with program I'm writing (novice programmer)



## Jarius (Jun 15, 2007)

I don't know if you can help me with this, but I figure it wouldn't hurt to ask. 

I'm making a program to draw the Mandelbrot Set in VB.NET 2003. Every time something obscures the drawing window, that part of the window gets erased, and I don't know why. Let me give you a few screenshots:



This is what it's supposed to look like, but when a message box pops up:





The part behind the message box disappears.






The same thing happens when I minimize and maximize again.


I put a redraw statement in the form paint event, and I thought that was all I had to do... but I guess not. I tried putting a redraw statement in the pictureBox paint event but that did nothing at all.

The answer is probably so simple it's ridiculous, but I'm completely self-taught and I get the feeling this is one of those things you have to be told.

I'm sorry to inflict such basic lack of knowledge on your eminent forum, but I have no idea what to do. :sad:

I've attached my source code so someone can look it over and tell me what I'm doing wrong, if they feel like wading through it. It's still in the beta stage and there are things I'm still planning on implementing, so it's kind of oddly put together.

Any help would be most appreciated.


----------



## MattBro (Nov 11, 2006)

I can't really say (Since I don't condone VB), but, I suggest you use one of the video API's of DirectX for such a thing (Such as DirectDraw) which would give you direct access to video hardware instead of fidling around with GDI.


----------



## Jarius (Jun 15, 2007)

When this problem first presented itself I tried learning DirectDraw to fix it, but it was so confusing that I gave it up and tried to stay with GDI. Are there any good online DirectDraw tutorials? A few google searches didn't turn up anything useful.

From what I saw, the biggest problem is that DirectDraw is being phased out, so there's not much info on it. They want you to use Direct3D instead of DirectDraw, but that's even more complicated to learn.


----------



## MattBro (Nov 11, 2006)

These tutorials are what I used (A google search for "DirectDraw MSDN Archive" will render these.)

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/ddraw7/directdraw7/ddover_7dx3.asp
http://msdn.microsoft.com/archive/en-us/dnardirdraw/html/msdn_directd5.asp?frame=true

Although DirectDraw is not supported, it will remain valid for the duration of DirectX; most likely will never become deprecated.

Direct3D isn't all that hard, hell I'm using Direct3D for terrain and DirectDraw for character sprites in an MMORPG. I'd suggest you learn C++ regardless.


----------



## Snake21605 (Oct 10, 2006)

What are your computer specs. I have that same problem on my lower end machines, but with my powerhouse(s).....Flawless


----------



## stirling (Jan 10, 2007)

This is a fundamental "feature" of window orientated GUIs. Whenever an area of screen realestate is exposed, something other than magic has to update that area. In VB6 the AutoRedraw property could be utilised to take care of this for you. For reasons that I'm sure make perfect sense to MS when they advanced VB6 to VB.NET this handy feature was omitted.
One generalized solution is to draw to a bitmap and then copy this bitmap to your form/picturebox whatever. Then when the form is exposed you re-copy the bitmap. However it's easy to see that this can be un-economical. i.e. even a tiny bit of the form being exposed will lead to the whole form being re-painted - often not a problem, but if it is you need to get creative - for example - copy only the bit of the bitmap representing the area that has actually been exposed rather than all of it.


----------



## Jarius (Jun 15, 2007)

To Stirling: I'm already doing the rendering on a back buffer, then assigning the buffer to the picturebox when rendering finishes. I also assign the back buffer to the picturebox again in the form.paint event... but apparently that's not enough. It works when I move the window offscreen and back, but not when something obscures only part of the window or when I minimize and restore.

I tried doing it in the picturebox.paint event, but not only did it not do anything at all, it also prevented the form.paint event from redrawing the picture.

To Mattbro: Thanks for the links. I've taken a couple C++ courses, but I only learned command line programming; I don't know how to program for the windows API in C++, which is why I decided to write this in VB.NET.


----------

