• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

can't draw on picture box background

i'm quite confused about the autoredraw property of a picture box.
I have a picture box pic1 with background picture. Now I allow the user to draw something on pic1 (something like the pen in MS paint).
However, I don't get to save the background picture together with the drawn lines as pic1.picture. I've tried setting the Autoredraw to T or F but I still can't get it.
I'm using the SavePicture method.

Is there another way or I did not set the autoredraw properly?
1 Solution
Hi !
OK, in this case. Set the
1) autoredraw = true
2) draw line or any other drawing operations.
3) autoredraw to false.
4) call savepicture.

Note: if you need to allow user to undo, add another picture with visible = false as double buffer for undo.

hOpe this'll help
set picture1.autoredraw = true
when you call savepicture use
savepicture picture1.image, "c:\temp\temp.bmp"

this should do it
teziAuthor Commented:
Sendoh, your method does not save what is drawn as part of the pic's picture. The pic.picture remains as it is.

Amir, your method actually works, but I also have something else which is copied  (bitblit) on pic1. So the method of Saving the image property actually serves as a "Printscreen" as well, so the unwanted pictures which are copied is also saved.

What I wanted is the pic1.Picture only contains its original picture and what is drawn on it only.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Hi !
OK, I'll explain further.

1) autoredraw = true
2) draw line or any other drawing operations.
3) autoredraw = false
4) assign confirm drawing by
        picture1.picture = picture1.image
5) call Bitblt to do whatever.
4) call savepicture by passing whether picture1.image(include bitblt) or picture1.picture where only original plus user drawing.

Hope it'll help ^_^.
teziAuthor Commented:
what you are actually doing is the same as what Amir has suggested. It still saves the whole image (including unwanted blit pictures on pic1) because you have assigned pic1.Image to pic1.Picture.

What I want is just the pic1.Picture saved together with the drawn lines only.
teziAuthor Commented:
Adjusted points to 50
Hi !
I think you didn't really tried it. Right ??
Anyway, I'd prove it to you.

Private Sub Command7_Click()
    Picture1.ScaleMode = 3
    Picture1.AutoRedraw = True
    Picture1.Circle (50, 50), 25
    Picture1.Picture = Picture1.Image
    Picture1.AutoRedraw = False
    BitBlt Picture1.hDC, 0, 0, 50, 50, Picture2.hDC, 0, 0, SRCCOPY
    SavePicture Picture1.Picture, "c:\temp\mci\save.bmp"
End Sub

Inthis case, whatever blitting on picture1.picture will not saved.
Does this suit your need ??
teziAuthor Commented:
I tried your codes already. Let me tell you why I think it does not work. I MUST call bitblt function first, and later I allow the user to draw on pic1. So the pic1.Image already contains the bitblt (the unwanted picture). So pic1.picture will contain EVERYTHING and not just its original background.
Hi there what you want to do is possible but it takes a little more work, depending on how much you want to bitblt and whether or not you want the user to be able to draw where you've blitted, etc.  Here's how you could do it.
Use a second picture box for the blting your doing set this 2nd box enabled to false

Keep this stuff in mind...
before you make this 2nd box visible, capture the other pic box's image where you intend on putting this box and blt it to this box, unless you just make it the same size and set the background = to the 1st pic(but if you do this you'll need to draw the users stuff twice one on orig and one on 2nd).  

    BitBlt Picture2.hDC, 0, 0, Picture2.Width, Picture2.Height, Picture1.hDC, Picture2.Left, Picture2.Top, SRCCOPY
    Picture2.Visible = True'set to false at design time
'note scale mode=pixel in container, you probably want to set
the 2nd box to be in the 1st box

Then you could blt whatever the heck you want to this and it won't be on the "original", and because it's enabled=false, the 1st box gets all the events.  Actually, if you allow the user to draw in your bitblt area then you'll need to do a test in the mousemove event if they're inside this 2ndbox and draw it on this box as well(the original still get's it drawing)  You also need to set this 2nd box autoredraw=true.  There's so many things you could do with this senerio, I don't have enough details to give you the exact route to go but this is definitely what you want.  You can test this by doing some drawing operations and then hide the 2nd box and you'll see the drawings underneath as well.
teziAuthor Commented:
I think you're very near to a solution already, but let me tell you what I'm trying to do so that you'll get a better idea and decide whether your method will work or not.

I have a few picture boxes, pic1 ,pic2, pic3 and pic4.
Pic1 is the main one with the background. Pic2, pic3,pic4 is inside pic1. All of them are set to autoredraw = True. pic2, pic3 and pic4 visible =False.

Next I call transparent blit to blit pic2, pic3 and pic4 on pic1. so far so good. Now I wanted to let the user moves pic2 , eg 5 pixels to the right, ok? I also let the user draw dots or lines (anywhere on pic1) so it may overlap on pic2,pic3 or pic4.

Since i'm using the transparent blit function, the pic2 will still be there even if i move the picture box to the right. So if I cls pic1, I would lost track of what the user has drawn...

So just wondering if your method (which is quite creative) will work. I need to keep track of what is drawn so that I can call the cls on pic1 and blit everything all over again on pic1 with pic2 having the new coordinates.

Can you give an example preferably with detection if the user draws on the blit pictures?
You might be of great help.TQ in advance.

teziAuthor Commented:
Hi mdougan

your codes work very perfectly, however there is one big major problem. I also have a few other picture boxes blit on pic1. So when I save the background, I also manage to save them as well. This is a good thing.

The bad thing is when I paste back the background on pic1, the partially "cut" pic3 which is blit on pic1 and is copied on picsAve will appear with the border. so pic3 looks kinda cut off into half.

One more thing, the user can draw inside the blit pictures. And when the background is pasted on it, the drawn lines is gone. :-(

ANy ideas?
teziAuthor Commented:
sorry about the that comment! pls ignore it.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now