can't draw on picture box background

Posted on 1999-01-11
Medium Priority
Last Modified: 2010-05-03
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?
Question by:tezi

Expert Comment

ID: 1455592
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

Expert Comment

ID: 1455593
set picture1.autoredraw = true
when you call savepicture use
savepicture picture1.image, "c:\temp\temp.bmp"

this should do it

Author Comment

ID: 1455594
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.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.


Expert Comment

ID: 1455595
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 ^_^.

Author Comment

ID: 1455596
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.

Author Comment

ID: 1455597
Adjusted points to 50

Expert Comment

ID: 1455598
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 ??

Author Comment

ID: 1455599
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.

Accepted Solution

Johnn earned 100 total points
ID: 1455600
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.

Author Comment

ID: 1455601
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.


Author Comment

ID: 1455602
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?

Author Comment

ID: 1455603
sorry about the that comment! pls ignore it.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question