Hi,

I work with Microsoft Visual Studio 2005.


I'm about to build a simple paint editor similar to MS Paint program.


of course, it has Edit menu, with Undo, Redo, Cut, Copy, Paste, Delete... etc.


I have a problem with Undo and Redo!

How to do them with drawing?

have I use Stack or something like this?

I'm just a beginner and I have no idea


Another question..

For Cut, Paste, Copy and Delete, I need a selection tool same as the one in MS Paint.
Where can I find it? or how to Cut and Paste with out it?

Please, I really need your help :)

thanx a lot.

Recommended Answers

All 15 Replies

Here is how I did a undo:

Dim UndoStack As New Stack(Of Bitmap)()    'holds the backup images

    '==========================================================================
    '   Saves the picture passed
    '==========================================================================
    Private Sub PushUndo(ByVal b As Bitmap)
        UndoStack.Push(b)
        btnUnDo.Visible = True
    End Sub

    '==========================================================================
    '   Returns the last picture saved
    '==========================================================================
    Private Function PopUndo() As Bitmap
        If UndoStack.Count = 0 Then
            Return Nothing
            btnUnDo.Visible = False
            Exit Function
        End If
        If UndoStack.Count = 1 Then btnUnDo.Visible = False
        Return UndoStack.Pop
    End Function

To save a bitmap:

'save the current picture for undo
        PushUndo(Display.Image.Clone)

To undo:

'==========================================================================
    '  pops the last bitmat off the stack and places it in the display
    '==========================================================================
    Private Sub btnUnDo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnDo.Click
        Dim bmp As Bitmap
        bmp = PopUndo()
        If bmp IsNot Nothing Then
            Display.Image = bmp
        End If
    End Sub

The second part I am going to have to find. I'll get back at you.

commented: That was good :) +2

waynespangler

thank u soooo mutch ..


I have a good idea now : )


thanks again

After all this time I finally found my bug in this routine. The undo button would never go off and I couldn't figure out why. Can you see it?

If UndoStack.Count = 0 Then
            Return Nothing
            btnUnDo.Visible = False
            Exit Function
        End If

In vb net a return exits the routine immediatlly so in the above btnUnDo.visible=False never got executed and neither did Exit Function. Because it was exiting I figured it was working right. Now I know why not.
It should be:

If UndoStack.Count = 0 Then
            btnUnDo.Visible = False
            Return Nothing
      End If

What are you using for the drawing, GDI+ ?

waynespangler..

ohhh .. yes that's right : )


thanx alooot

jbennet..

The drawing tool bar contains:

  • Lines (in different styles : regular, dashed and thick)
  • curves
  • Shapes: rectangle, circle and oval.
  • Pen.
  • Brush ( in different styles- HatchBrush, LinearGradientBrush, PathGradientBrush and TextureBrush)
  • Text.
  • Fill (with color or pattern)

and I drow on picture box


thank u : )

Here is some samples of cut, copy and paste. They are not as effecient as they should be, so that is up to you. Post if you have any more questions.

waynespangler..

thnx alooot : )

I did my project, and it's perfect now

thnx again ;)

Hi

please i want to ask about this statment

PushUndo(Display.Image.Clone)

Display is't the surface i draw on it??

i use a picture box for drawing and i don't want just the back ground image to be save

what about the drawings like lines,curves...etc??

please i need your healp

see ya

plz Nana can you help me ??

i've similar assignment and i need a little help

I'm just a beginner :(

Display is a picture box. It is what I named it. Just change the display name for whatever name you have for your picturebox.

Thanks waynespangler..

but howe can i save the contents of a picture box (not only the background image) in a bitmap???

PictureBox1.Image.Save("c:\test.gif", Imaging.ImageFormat.Gif)

Hello,
When my application is run there is a picture box with a city map
and a save button to save this image in the picture box.

Before saving the image I would like to indicate few buildings, streets etc
using concentric circles and ovals.

Here is how I do it
On double click of picturebox do the following
Graphics *g=Graphics::FromImage(this->pictureBox1->Image);
g->DrawEllipse(pen1,90,90,70,70);
g->DrawEllipse(pen1,45,45,65,65);

This draws a concentric circles but the problem is I would like it to be red
in colour(this is not a problem) and transparent (this is).

The next question is the user should be able to draw ovals (red, transparent) and
the user should be able to rotate this oval to pinpoint something on the map.
Thanks in advance for any help.
Mintara

Hi,

I work with Microsoft Visual Studio 2005.


I'm about to build a simple paint editor similar to MS Paint program.


of course, it has Edit menu, with Undo, Redo, Cut, Copy, Paste, Delete... etc.


I have a problem with Undo and Redo!

How to do them with drawing?

have I use Stack or something like this?

I'm just a beginner and I have no idea


Another question..

For Cut, Paste, Copy and Delete, I need a selection tool same as the one in MS Paint.
Where can I find it? or how to Cut and Paste with out it?

Please, I really need your help :)

thanx a lot.

Create a pen with transparent color as:

Dim p As New Pen(Color.FromArgb(126, 255, 255, 0))
        p.Width = 5
        g.DrawEllipse(p, New Rectangle(50, 50, 50, 50))

The 126 makes the yellow half transparent.

Hi, sorry for intruding. I'm a VB newbie. I wanna ask about this part of the code:

'save the current picture for undo
PushUndo(Display.Image.Clone)

^where do I put this code? Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.