Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 224591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:19:52+00:00 2026-05-11T19:19:52+00:00

I have a problem with my code after I click undo I can’t draw

  • 0

I have a problem with my code

after I click undo I can’t draw on the image and I don’t know why

this is my code

Imports System.Drawing.Graphics
Imports System.Drawing.Bitmap
Imports System.Drawing
Public Class FrmChild
    Dim Xstart As Short
    Dim Ystart As Short
    Dim Xend As Short
    Dim Yend As Short
    Dim BoolErasing As Boolean = False
    Dim BoolDrawing As Boolean = False
    Dim Image As New Bitmap(1500, 1200)
    Public GraphFun As Graphics = Graphics.FromImage(Image)
    Dim ErasingPen As New Pen(Drawing.Color.White, 3)
    Dim DrawingPen As New Pen(Drawing.Color.Black, 3)
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        undo.Push(Image.Clone())
        redo.Clear()
        btnredo.Enabled = False
        If Not btnundo.Enabled Then btnundo.Enabled = True
        Xstart = e.X
        Ystart = e.Y
        If btnEraser Then
            BoolErasing = True
        ElseIf btnPencil Then
            BoolDrawing = True
        End If
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If BoolErasing Then
            GraphFun.DrawLine(ErasingPen, Xstart, Ystart, e.X, e.Y)
        ElseIf BoolDrawing Then
            GraphFun.DrawLine(DrawingPen, Xstart, Ystart, e.X, e.Y)
        End If
        Xstart = e.X
        Ystart = e.Y
        PictureBox1.Image = Image
    End Sub

    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        Xend = e.X
        Yend = e.Y
        BoolErasing = False
        BoolDrawing = False
        PictureBox1.Image = Image
    End Sub


    Private Sub Btnundo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnundo.Click
        If Not btnredo.Enabled Then btnredo.Enabled = True
        redo.Push(Image.Clone())
        Image = undo.Pop()
        PictureBox1.Image = Image
        If undo.Count = 0 Then
            btnundo.Enabled = False
        End If
    End Sub


    Private Sub FrmChild_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        btnundo.Enabled = False
        btnredo.Enabled = False
    End Sub

    Private Sub btnredo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnredo.Click
        If Not btnundo.Enabled Then btnundo.Enabled = True
        undo.Push(Image.Clone())
        Image = redo.Pop()
        PictureBox1.Image = Image
        If redo.Count = 0 Then btnredo.Enabled = False
    End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:19:52+00:00Added an answer on May 11, 2026 at 7:19 pm

    That’s because you are creating a Graphics object for a specific Bitmap object. You can only use that to draw on that specific bitmap, when you replace the bitmap with one from the undo, you are still drawing on the same bitmap, but that one is not displayed any more.

    Instead of creating a Graphics object and holding on to it, create one for the current bitmap when you need it, and dispose of it afterwards:

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
       Using graphFun As Graphics = Graphics.FromImage(Image)
          If BoolErasing Then
             GraphFun.DrawLine(ErasingPen, Xstart, Ystart, e.X, e.Y)
          ElseIf BoolDrawing Then
             GraphFun.DrawLine(DrawingPen, Xstart, Ystart, e.X, e.Y)
          End If
       End Using
       Xstart = e.X
       Ystart = e.Y
       PictureBox1.Image = Image
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 212k
  • Answers 212k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I found two possible solutions: One is to write a… May 12, 2026 at 10:22 pm
  • Editorial Team
    Editorial Team added an answer select c.id, c.name, p.name, p.pointid, p2.pointid, p2.name from tblchildinfo c… May 12, 2026 at 10:22 pm
  • Editorial Team
    Editorial Team added an answer Consider this piece of code first int *function(); ... *function()… May 12, 2026 at 10:22 pm

Related Questions

I have a problem with my code after I click undo I can't draw
I have a WPF Popup control with a ListBox and a Button in it.
The code goes something like this: protected bool IsOKToSend() { bool IsOK = true;
I have a small problem with the SWFObject on my web page. The behavior
I have a regular .NET Windows Forms treeview control. The nodes are setup like

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.