954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

simple paint similar to MS Paint.. I have qustions!

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.

Nana.vb
Newbie Poster
4 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

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.

waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

waynespangler

thank u soooo mutch ..


I have a good idea now : )


thanks again

Nana.vb
Newbie Poster
4 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

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
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

What are you using for the drawing, GDI+ ?

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

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 : )

Nana.vb
Newbie Poster
4 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

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.

Attachments Rubberband.zip (642.88KB)
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

waynespangler..

thnx alooot : )

I did my project, and it's perfect now

thnx again ;)

Nana.vb
Newbie Poster
4 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

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

WoW7787
Newbie Poster
3 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

plz Nana can you help me ??

i've similar assignment and i need a little help

I'm just a beginner :(

WoW7787
Newbie Poster
3 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

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

waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

Thanks waynespangler..

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

WoW7787
Newbie Poster
3 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

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

waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

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.
mintara
Newbie Poster
1 post since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

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.

waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

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.

dyahalifda
Newbie Poster
11 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You