hi folks,
I'm writing a program for a punch press that displays the pattern to be punched. I have learned how to retrieve the data from a spreadsheet calculate the hole angles and draw them on my form

{ Using g As Graphics = Me.CreateGraphics
            Dim pn As New Pen(Color.Crimson, 3)
            Dim circ As New Rectangle((xdrawloc), (ydrawloc), 12, 12)
            g.DrawEllipse(pn, circ)

            xloc.Add(xdrawloc)
            yloc.Add(ydrawloc)
        End Using}

The basic pattern has multiple holes and is different for each process. As the machine runs it fills in the holes and changes colors.

My problem is when the form is minimized and then reopened all the graphics are gone. If the program is running then it keeps adding drawings to the screen but the prior screen drawings have been erased. How do i retain all the drawings that are getting placed on the screen when it is minimized. It's probably an asy answer but i'm new and going in the circles i'm trying to draw.

Instead of using the form graphics use a bitmap and set the form background equal to the bitmap image. Now when you write to the bitmap it will be transfered automatically to the form background image. Otherwise you have to do all your drawing in the form paint event and call Form.Invalidate.

create a new project and add this code. Start it with the window minimized.

Public Class Form1
    Private bmp As Bitmap = New Bitmap(100, 200, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
    Private gr As Graphics = Graphics.FromImage(bmp)

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.BackgroundImageLayout = ImageLayout.None
        Me.BackgroundImage = bmp
        gr.FillEllipse(Brushes.Blue, New Rectangle(0, 0, 100, 200))
    End Sub

End Class

Thanks,Wayne
I'll give it a try. It's a very dynamic drawing containing up to 600 circle targets for several hundred different patterns. The code I have already wrote works so well until you minimize it then poof it's all gone. I guess it's part of the learning process. Your code did make the lights come on though and i can't wait to see the results. I'll hack on it some more tomorrow. Love west Virginia by the way spend a lot of time up at Cass, my wife and I are steam engine railroad fans

Yea, love Cass myself. This summer we are going to take the Mistery Train ride and see if I'm smart enought to solve the crime. I was away from West Virginia for 40 years and now I will never leave it again.

You might be able to put the code in Form.Paint but I think it will slow up your drawing because you have to keep drawing everything. With the bitmap you draw to it once and keep adding more. You don't need to draw anything you already drew.

If you can convert to drawing to bitmap I think in the long run it would be worth your extra time.

Got it!!!

Thanks for your help, ended up using a picturebox instead of writing on the form but it does retain it now that it is a bitmap and using the picturebox helped keep everything in order when changing aspect ratios. Now i've got to start integrating it to the machine. OPC time, back to the books. thanks again!!

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.