can't draw on picture box background

Posted on 1999-01-11
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.
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


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 50 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now