This is a distraction task in a Psychologgy experiment. For a period of 5 mins the user moves a pic box from the centre of the panel to a matching triangle. The picbox mouseup detects which region it is and adds a score and then sets it back to the middle screen. However after several drag/drops the program crashes with the "A generic error occurred in GDI+" message. This is not specific enough to tell me what the problem is, is it painting the panel over and over again and running out of resources? Any ideas?

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Dim myGraphicsPath As New GraphicsPath
        'Define the 3 points of the triangle.>>
        Dim point1 As New Point(0, 0)
        Dim point2 As New Point(300, 0)
        Dim point3 As New Point(0, 300)

        'Horizontal line.>>
        myGraphicsPath.AddLine(point1.X, point1.Y, point2.X, point2.Y)

        'Vertical line.>>
        myGraphicsPath.AddLine(point1.X, point1.Y, point3.X, point3.Y)

        'Horizontal line.>>
        myGraphicsPath.AddLine(point3.X, point3.Y, point2.X, point2.Y)

        Dim myRegion1 As New Region(myGraphicsPath)
        Dim myBrush As New SolidBrush(Color.Black)
        e.Graphics.FillRegion(myBrush, myRegion1)

        ptrRegion1 = myRegion1.GetHrgn(e.Graphics)
        myRegion1.Dispose()



        '2nd triangle code, this is for the green one.>>

        Dim point4 = New Point(700, 0)
        Dim point5 = New Point(1000, 0)
        Dim point6 = New Point(1000, 300)
        Dim graphicsPath2 As New GraphicsPath
        Dim myRegion2 As New Region(myGraphicsPath)

        graphicsPath2.AddLine(point4.X, point4.Y, point5.X, point5.Y)
        graphicsPath2.AddLine(point4.X, point4.Y, point6.X, point6.Y)
        graphicsPath2.AddLine(point6.X, point6.Y, point5.X, point5.Y)

        myRegion2 = New Region(graphicsPath2)

        myBrush = New SolidBrush(Color.White)

        e.Graphics.FillRegion(myBrush, myRegion2)
        ptrRegion2 = myRegion2.GetHrgn(e.Graphics)
        myRegion2.Dispose()


        '3rd triangle code, this is for the yellow one.>>
        Dim point7 = New Point(0, 400)
        Dim point8 = New Point(0, 700)
        Dim point9 = New Point(300, 700)
        Dim myRegion3 As New Region(myGraphicsPath)
        Dim graphicsPath3 As New GraphicsPath

        graphicsPath3.AddLine(point7.X, point7.Y, point8.X, point8.Y)
        graphicsPath3.AddLine(point7.X, point7.Y, point9.X, point9.Y)
        graphicsPath3.AddLine(point9.X, point9.Y, point8.X, point8.Y)

        myRegion3 = New Region(graphicsPath3)
        myBrush = New SolidBrush(Color.Yellow)

        e.Graphics.FillRegion(myBrush, myRegion3)
        ptrRegion3 = myRegion3.GetHrgn(e.Graphics)
        myRegion3.Dispose()

        '4th triangle code, this is for the blue one.>>
        Dim point10 = New Point(700, 700)
        Dim point11 = New Point(1000, 700)
        Dim point12 = New Point(1000, 400)
        Dim myRegion4 As New Region(myGraphicsPath)
        Dim graphicsPath4 As New GraphicsPath

        graphicsPath4.AddLine(point10.X, point10.Y, point11.X, point11.Y)
        graphicsPath4.AddLine(point10.X, point10.Y, point12.X, point12.Y)
        graphicsPath4.AddLine(point12.X, point12.Y, point11.X, point11.Y)

        myRegion4 = New Region(graphicsPath4)
        myBrush = New SolidBrush(Color.Blue)

        e.Graphics.FillRegion(myBrush, myRegion4)
        ptrRegion4 = myRegion4.GetHrgn(e.Graphics)
        myRegion4.Dispose()
        myBrush.Dispose()
        myGraphicsPath.Dispose()
        graphicsPath2.Dispose()
        graphicsPath3.Dispose()
        graphicsPath4.Dispose()

    End Sub

>A generic error occurred in GDI+.

Are you saving a bitmap or something like that?

No, not saving anything, just incrementing an integer when the picbox is dropped on the triangle.

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.