?
Solved

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

Posted on 2003-03-19
9
Medium Priority
?
176 Views
Last Modified: 2010-05-01
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
Comment
Question by:gemstarmew
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 8168279
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
 
LVL 22

Expert Comment

by:rspahitz
ID: 8168314
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
 
LVL 8

Assisted Solution

by:List244
List244 earned 105 total points
ID: 8169372
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!

 

Author Comment

by:gemstarmew
ID: 8175555
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
 
LVL 22

Expert Comment

by:rspahitz
ID: 8175691
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
 

Author Comment

by:gemstarmew
ID: 8225280
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
 
LVL 8

Expert Comment

by:List244
ID: 8227727
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
 
LVL 22

Accepted Solution

by:
rspahitz earned 105 total points
ID: 8227810
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
 

Expert Comment

by:CleanupPing
ID: 8531986
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

Industry Leaders: 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!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

771 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