I am in the process of writing a graphing calculator (just for fun) and I just coded a function that will draw the axes on the graph. Before testing, I could successfully run my program. Now, however, it stops debugging and gives me the error in the title.
Here's the complete error it gives me in the output module:
A first chance exception of type 'System.NullReferenceException' occurred in Graphing Calculator.exe
An unhandled exception of type 'System.InvalidOperationException' occurred in Graphing Calculator.exe
Additional information: An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
The program '[6560] Graphing Calculator.vshost.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).
I'm not sure why it's doing this, and have searched for a few hours trying to resolve this (which seems to be decently common) to no avail. I have attatched a .zip folder (Graphing Calculator.zip) of my project to this post if you want to take a look at it. Also, here is my code for drawing the axes:
Private Function drawScale()
        Dim n As Integer
        Dim G As Graphics
        G = pbGraphGraphics.CreateGraphics
        xSclPxl = pbGraphGraphics.Width / ((xMin - xMax) / xScl)
        ySclPxl = pbGraphGraphics.Height / ((yMin - yMax) / yScl)
        Dim xTcks As Decimal = (xMax - xMin) / xScl
        Dim yTcks As Decimal = (yMax - yMin) / yScl

        'DRAWS X-AXIS
        Dim xx1 As Decimal = pbGraphGraphics.Left
        Dim xx2 As Decimal = pbGraphGraphics.Left + pbGraphGraphics.Width
        Dim xy1 As Decimal = pbGraphGraphics.Top + pbGraphGraphics.Height / (yMax / ySclPxl)
        Dim xy2 As Decimal = xy1
        G.DrawLine(Pens.Black, xx1, xy1, xx2, xy2)
        'DRAWS Y-AXIS
        Dim yx1 As Decimal = pbGraphGraphics.Left + pbGraphGraphics.Width / (xMax / xSclPxl)
        Dim yx2 As Decimal = yx1
        Dim yy1 As Decimal = pbGraphGraphics.Top
        Dim yy2 As Decimal = pbGraphGraphics.Top + pbGraphGraphics.Height
        G.DrawLine(Pens.Black, yx1, yx2, yy1, yy2)

        n = 1
        Dim xtx1 As Decimal = pbGraphGraphics.Left
        Dim xtx2 As Decimal = pbGraphGraphics.Left + (xSclPxl * n)
        Dim xty1 As Decimal = xy1 - 2
        Dim xty2 As Decimal = xy1 + 2
        Dim xt As Integer = 0
        For xt = 0 To ((xMax - xMin) / xScl)
            G.DrawLine(Pens.Black, xtx1, xty1, xtx2, xty2)
            n = n + 1
            xtx2 = pbGraphGraphics.Left + (xSclPxl * n)

        n = 1
        Dim ytx1 As Decimal = yx1 - 2
        Dim ytx2 As Decimal = yx1 + 2
        Dim yty1 As Decimal = pbGraphGraphics.Top
        Dim yty2 As Decimal = pbGraphGraphics.Top + (ySclPxl * n)
        Dim yt As Integer = 0
        For yt = 0 To ((yMax - yMin) / yScl)
            G.DrawLine(Pens.Black, ytx1, yty1, ytx2, yty2)
            n = n + 1
            ytx2 = pbGraphGraphics.Left + (ySclPxl * n)

    End Function
Even after commenting this out and getting rid of the places where it's called, my program still doesn't function and gives me the same error. Any help is greatly appreciated! Thanks!