Link to home
Start Free TrialLog in
Avatar of gemstarmew
gemstarmewFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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.
Avatar of rspahitz
rspahitz
Flag of United States of America image

This overlaps with the discussion going on here: https://www.experts-exchange.com/questions/20556199/picturebox-problem-how-to-undo-lines.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.
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.
SOLUTION
Avatar of List244
List244

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gemstarmew

ASKER

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,
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.
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 :)
Avatar of List244
List244

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.