Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Help! Paint Program, layers, also undo/redo...

I've been creating a basic paint program and i've been trying to figure out how to make a foreground and background layer on my PictureBox, the picture box is named "Canvas" how would i go about creating a foreground and background layer? i was going to add a command button so the user can click on it and it will switch layers.. help?

Also i wanted to create an undo redo system for the paint program, (i thought about this when it started to get annoying when you made mistakes drawing in it.)

For the foreground and background swicther button i was going to make a command button that when you click on it it switches its caption everytime its clicked, like original state would be background. The user clicks on it and the layer they are on would be switched to foreground, and the command button would save foreground on it. I couldn't figure how to do any of this, thank you for your help or direction.
0
gemstarmew
Asked:
gemstarmew
  • 4
  • 2
  • 2
  • +1
2 Solutions
 
rspahitzCommented:
This overlaps with the discussion going on here: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20556199.html

The layer idea is difficult to implement because the picture box does not support transparency.

However, by implementing image controls combined with pictureboxes, you may be able to solve this.

The main thing is that you'll probably need to transfer between the "current" image to the work area, allow the user to make changes, then restore the image when done.
0
 
rspahitzCommented:
Actually, a bit more help:

You can intercept the mousedown/mouseup events for an image control to draw onto a picture box located underneath an image control.  This will allow you to capture this drawing on a layer.

I'd probably handle it by creating an image layer array and having a picturebox workarea which appears when the user attempts to draw on a certain layer.  At that point, the image should be transferred to the picturebox so that action can be performed on that layer.  When the layer changes, update the image from the picturebox to the layer, then switch to the new layer and repeat the process.
0
 
List244Commented:
For Background/ForeGround, you can have to seperate picture boxes, one forground one background and use BitBlt to combine the two, obviously copy the background before copying the foreground to the picture
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gemstarmewAuthor Commented:
Thanks for replying so soon :)

I need to try it when i get home, thanks for the related thread about undo/redo, thats helped alot. About the intercepting the mouseup/mousedown would you be able to point me in the direction of an example? I'm quite new to VB so i haven't picked up alot of the phrasing :(

Also thanks for the reply List :) i'll try both tonight when i get back,
0
 
rspahitzCommented:
To start, use this:

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = vbLeftButton Then
    Picture1.PSet (X, Y), vbRed
  End If
End Sub

If you need to keep track of other things when the mouse down or up occurs, intercept that in the corresponding procedure.  You may also need some module-level variables, which are defined at the top of the code window:

private m_sngStartingX as single
private m_sngStartingY as single

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  m_sngStartingX = X
  m_sngStartingY = Y
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Picture1.Line (m_sngStartingX, m_sngStartingY)-(X, Y), vbGreen
End Sub

--
Combined, all of the above procedures lets the user draw in red inside a picturebox by clicking the mouse and dragging.  when the mouse button is released, a line is drawn from the starting point to the ending point.

You can obviously customize this as needed.
0
 
gemstarmewAuthor Commented:
Thanks so much for the help, sorry i didn't reply sooner i lost this site address. Is there a way that i could split the points between you two?

The two bits about the layers have shown me how i could possibly try it, so its helped alot more than i expected,

When i was talking about the intercepting the mouseup/mousedown, i've already made the code for the actual drawing on an picture box. I should have made my question clearer, i was wondering about the bit where you said "draw onto a picture box located underneath an image control" i wondered if i could get an example of that.

Thanks so much again :)
0
 
List244Commented:
Im a bit confused as of what you want an example of, but here is an example of having a forground picture and a background, then using them to create a final picture.

www.jemisp.com/visualcode/desktop.zip

This example, i did not add drawing as you said youve done that already, also it assumes pictures are equal size. What it does is load the background picture, then draw the foreground(without any spots that are "transparent") It has an example of how you can do it with Win2000 and up systems as well as one for win98 and below.
0
 
rspahitzCommented:
Place the image control inside the picturebox, then:

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = vbLeftButton Then
    Picture1.PSet (X + Image1.Left, Y + Image1.Top), vbBlue
  End If
End Sub

This will draw onto the picturebox.  Then you can transfer the image back to the image control:

Image1.Picture = Picture1.Image
Picture1.Cls

If you make sure the image control is always at (0,0), you don't have to worry about alignment/cropping issues.
0
 
CleanupPingCommented:
Hi gemstarmew,
This old question (QID 20556367) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now