Public Sub DrawBitMap(ByVal inputX As Integer, ByVal inputY As Integer, ByVal ZoomFactor As Single, ByRef SC_BitMap As Bitmap)

        'This function is used to draw the electric line and equipment blocks on top of Bing Maps areal imagery for the Web Map App.
        'The map itself is actually a button with a WebUserControl on top of it, everytime the button is pressed the page reloads 
        'and the map draws itself in less than a second using this function based on the coordinates clicked and which zoom function
        'is chosen in the buttons on the right. 

        Dim X_Pos As Integer
        Dim Y_Pos As Integer
        Dim App_Resolution As Integer
        App_Resolution = 192
        Dim maxX As Integer, maxY As Integer, minX As Integer, minY As Integer
        Dim PlineTileIndexStart() As Integer
        Dim PlineTileIndexStop() As Integer
        Dim BlockTileIndexStart() As Integer
        Dim BlockTileIndexStop() As Integer
        Dim AttTileIndexStart() As Integer
        Dim AttTileIndexStop() As Integer
        Dim StartBottom As Integer
        Dim StartLeft As Integer
        Dim LineStr As String
        Dim handle As Integer
        Dim LayerIndex As Integer
        Dim LayerArray() As LayerStruct
        Dim Visible As Integer

        X_Pos = inputX
        Y_Pos = inputY

        If App_Resolution = 96 Then
            maxX = X_Pos + (100 * (1 + ZoomFactor))
            maxY = Y_Pos + (100 * (1 + ZoomFactor))
            minX = X_Pos - (100 * (1 + ZoomFactor))
            minY = Y_Pos - (100 * (1 + ZoomFactor))
        ElseIf App_Resolution = 192 Then
            maxX = X_Pos + (388 * (1 + ZoomFactor))
            maxY = Y_Pos + (272 * (1 + ZoomFactor))
            minX = X_Pos - (388 * (1 + ZoomFactor))
            minY = Y_Pos - (272 * (1 + ZoomFactor))
        End If

        Dim BottomTileRow As Integer
        Dim TopTileRow As Integer
        Dim LeftTileRow As Integer
        Dim RightTileRow As Integer
        Dim TILENUMX As Integer
        Dim TILENUMy As Integer

        Dim fsPlines As FileStream
        Dim fsPlinePoints As FileStream
        Dim fsRecIdx As FileStream
        Dim fsBlockRefs As FileStream
        Dim fsBlockRecIdx As FileStream
        Dim fsAttRefs As FileStream
        Dim fsAttRecIdx As FileStream
        Dim fsLyrArray As FileStream
        Dim fsBlkMetaTileIdx As FileStream
        Dim fsBlkPlines As FileStream
        Dim fsBlkText As FileStream
        Dim fsBlkPlinePoints As FileStream
        Dim i As Integer
        Dim brPlines As BinaryReader
        Dim brPlinePoints As BinaryReader
        Dim brRecIdx As BinaryReader
        Dim brBlockRefs As BinaryReader
        Dim brBlockRecIdx As BinaryReader
        Dim brAttRefs As BinaryReader
        Dim brAttRecIdx As BinaryReader
        Dim brLyrArray As BinaryReader
        Dim brBlkMetaTileIdx As BinaryReader
        Dim brBlkPlines As BinaryReader
        Dim brBlkText As BinaryReader
        Dim brBlkPlinePoints As BinaryReader
        Dim unUsed As Integer
        Dim InsertX As Single
        Dim InsertY As Single
        Dim OwnerId As Integer
        Dim Rotation As Integer
        Dim BlkRotation As Single
        Dim ScaleFactor As Integer
        Dim recStart As Integer
        Dim recStop As Integer
        Dim NewX As Single, NewY As Single

        Dim SiteFolder As String
        Dim AppPath As String, PhysicalPath As String

        AppPath = HttpContext.Current.Request.ApplicationPath
        PhysicalPath = HttpContext.Current.Request.MapPath(AppPath)


        SiteFolder = System.Configuration.ConfigurationManager.AppSettings("WebSiteFolder")


        'First we bring in each of the dat files needed into arrays that can be accessed quickly to draw the features
        Dim SPCoordsTable() As SPCoords
        Dim numBytes As Integer
        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\Coordinates\SPCoordsTable.dat") Then
            fsRecIdx = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\Coordinates\SPCoordsTable.dat", FileMode.Open, FileAccess.Read)
            numBytes = fsRecIdx.Length
            ReDim SPCoordsTable(numBytes / 24)
            Dim ByteArray() As Byte
            Dim TempStruct As SPCoords
            brRecIdx = New BinaryReader(fsRecIdx)

            ByteArray = brRecIdx.ReadBytes(numBytes)
            Dim ptr As IntPtr = LocalAlloc(LPTR, Marshal.SizeOf(TempStruct))
            For i = 0 To 1 '(numBytes / 24) - 1
                Marshal.Copy(ByteArray, i * 24, ptr, 24)
                TempStruct = Marshal.PtrToStructure(ptr, New SPCoords().GetType)
                SPCoordsTable(i) = TempStruct

                SPCoordsTable(i).SP_X = SPCoordsTable(i).SP_X
                SPCoordsTable(i).SP_Y = SPCoordsTable(i).SP_Y
            Next i
            brRecIdx.Close()
            fsRecIdx.Close()
            ReDim ByteArray(0)

            StartLeft = SPCoordsTable(0).SP_X
            StartBottom = SPCoordsTable(0).SP_Y
        End If
        fsRecIdx = Nothing
        brRecIdx = Nothing

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\PlineTileIndex.dat") Then
            fsRecIdx = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\PlineTileIndex.dat", FileMode.Open, FileAccess.Read)
            numBytes = fsRecIdx.Length
            ReDim PlineTileIndexStart(numBytes / 8)
            ReDim PlineTileIndexStop(numBytes / 8)
            Dim ByteArray() As Byte
            Dim TempStruct As TileStruct
            brRecIdx = New BinaryReader(fsRecIdx)

            ByteArray = brRecIdx.ReadBytes(numBytes)
            Dim ptr As IntPtr = LocalAlloc(LPTR, Marshal.SizeOf(TempStruct))
            For i = 0 To (numBytes / 8) - 1
                Marshal.Copy(ByteArray, i * 8, ptr, 8)
                TempStruct = Marshal.PtrToStructure(ptr, New TileStruct().GetType)
                PlineTileIndexStart(i) = TempStruct.Start
                PlineTileIndexStop(i) = TempStruct.Stp
            Next i

            brRecIdx.Close()
            fsRecIdx.Close()
            ReDim ByteArray(0)
        End If
        fsRecIdx = Nothing
        brRecIdx = Nothing

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\blkTileIndex.dat") Then
            fsRecIdx = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\blkTileIndex.dat", FileMode.Open, FileAccess.Read)
            numBytes = fsRecIdx.Length
            ReDim BlockTileIndexStart(numBytes / 8)
            ReDim BlockTileIndexStop(numBytes / 8)
            Dim ByteArray() As Byte
            Dim TempStruct As TileStruct
            brRecIdx = New BinaryReader(fsRecIdx)

            ByteArray = brRecIdx.ReadBytes(numBytes)
            Dim ptr As IntPtr = LocalAlloc(LPTR, Marshal.SizeOf(TempStruct))
            For i = 0 To (numBytes / 8) - 1
                Marshal.Copy(ByteArray, i * 8, ptr, 8)
                TempStruct = Marshal.PtrToStructure(ptr, New TileStruct().GetType)
                BlockTileIndexStart(i) = TempStruct.Start
                BlockTileIndexStop(i) = TempStruct.Stp
            Next i

            brRecIdx.Close()
            fsRecIdx.Close()
            ReDim ByteArray(0)
        End If
        fsRecIdx = Nothing
        brRecIdx = Nothing

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\attTileIndex.dat") Then
            fsRecIdx = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\attTileIndex.dat", FileMode.Open, FileAccess.Read)
            numBytes = fsRecIdx.Length
            ReDim AttTileIndexStart(numBytes / 8)
            ReDim AttTileIndexStop(numBytes / 8)
            Dim ByteArray() As Byte
            Dim TempStruct As TileStruct
            brRecIdx = New BinaryReader(fsRecIdx)

            ByteArray = brRecIdx.ReadBytes(numBytes)
            Dim ptr As IntPtr = LocalAlloc(LPTR, Marshal.SizeOf(TempStruct))
            For i = 0 To (numBytes / 8) - 1
                Marshal.Copy(ByteArray, i * 8, ptr, 8)
                TempStruct = Marshal.PtrToStructure(ptr, New TileStruct().GetType)
                AttTileIndexStart(i) = TempStruct.Start
                AttTileIndexStop(i) = TempStruct.Stp
            Next i

            brRecIdx.Close()
            fsRecIdx.Close()
            ReDim ByteArray(0)
        End If

        fsRecIdx = Nothing
        brRecIdx = Nothing

        Dim steve As String
        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\LyrArray.dat") Then
            fsLyrArray = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\LyrArray.dat", FileMode.Open, FileAccess.Read)
            numBytes = fsLyrArray.Length
            ReDim LayerArray(numBytes / 110)

            brLyrArray = New BinaryReader(fsLyrArray)

            For i = 0 To (numBytes / 110) - 1
                If fsLyrArray.Position <> ((i) * 110) Then
                    fsLyrArray.Seek(((i) * 110), SeekOrigin.Begin)
                End If
                LayerArray(i).LyrName = brLyrArray.ReadChars(50)
                steve = LayerArray(i).LyrName
                If fsLyrArray.Position <> (((i) * 110) + 50) Then
                    fsLyrArray.Seek((((i) * 110) + 50), SeekOrigin.Begin)
                End If
                LayerArray(i).isActiveLayer = brLyrArray.ReadInt16
                steve = LayerArray(i).isActiveLayer
                LayerArray(i).isOn = brLyrArray.ReadInt16
                steve = LayerArray(i).isOn
                LayerArray(i).Color = brLyrArray.ReadInt32
                steve = LayerArray(i).Color
                LayerArray(i).LineType = brLyrArray.ReadInt16
                steve = LayerArray(i).LineType
            Next i

            brLyrArray.Close()
            fsLyrArray.Close()

        End If
        fsLyrArray = Nothing
        brLyrArray = Nothing


        'The rest of the Dat files are too big to bring into arrays quickly so we connect FileStreams to them to be used to quickly pull data while drawing

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\NewPlines.dat") Then
            fsPlines = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\NewPlines.dat", FileMode.Open, FileAccess.Read)
            brPlines = New BinaryReader(fsPlines)
        Else
            Exit Sub
        End If

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\PlinePoints.dat") Then
            fsPlinePoints = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\PlinePoints.dat", FileMode.Open, FileAccess.Read)
            brPlinePoints = New BinaryReader(fsPlinePoints)
        Else
            Exit Sub
        End If

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\PlineRecordIndex.dat") Then
            fsRecIdx = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\PlineRecordIndex.dat", FileMode.Open, FileAccess.Read)
            brRecIdx = New BinaryReader(fsRecIdx)
        Else
            Exit Sub
        End If

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\blkRecordIndex.dat") Then
            fsBlockRecIdx = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\blkRecordIndex.dat", FileMode.Open, FileAccess.Read)
            brBlockRecIdx = New BinaryReader(fsBlockRecIdx)
        Else
            Exit Sub
        End If

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\NewBlockRefs.dat") Then
            fsBlockRefs = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\NewBlockRefs.dat", FileMode.Open, FileAccess.Read)
            brBlockRefs = New BinaryReader(fsBlockRefs)
        Else
            Exit Sub
        End If

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\Blocks\BlocksTileIndex.dat") Then
            fsBlkMetaTileIdx = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\Blocks\BlocksTileIndex.dat", FileMode.Open, FileAccess.Read)
            brBlkMetaTileIdx = New BinaryReader(fsBlkMetaTileIdx)
        Else
            Exit Sub
        End If

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\Blocks\BlocksPlines.dat") Then
            fsBlkPlines = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\Blocks\BlocksPlines.dat", FileMode.Open, FileAccess.Read)
            brBlkPlines = New BinaryReader(fsBlkPlines)
        Else
            Exit Sub
        End If

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\Blocks\BlocksPlinePoints.dat") Then
            fsBlkPlinePoints = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\Blocks\BlocksPlinePoints.dat", FileMode.Open, FileAccess.Read)
            brBlkPlinePoints = New BinaryReader(fsBlkPlinePoints)
        Else
            Exit Sub
        End If

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\Blocks\BlocksBlkText.dat") Then
            fsBlkText = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\Blocks\BlocksBlkText.dat", FileMode.Open, FileAccess.Read)
            brBlkText = New BinaryReader(fsBlkText)
        Else
            Exit Sub
        End If

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\attRecordIndex.dat") Then
            fsAttRecIdx = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\attRecordIndex.dat", FileMode.Open, FileAccess.Read)
            brAttRecIdx = New BinaryReader(fsAttRecIdx)
        Else
            Exit Sub
        End If

        If File.Exists(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\NewAttRefs.dat") Then
            fsAttRefs = New FileStream(PhysicalPath & "\" & Session("Login_Company") & "\ExistingMapForWeb\NewAttRefs.dat", FileMode.Open, FileAccess.Read)
            brAttRefs = New BinaryReader(fsAttRefs)
        Else
            Exit Sub
        End If

        'Figure out which Tiles need drawn for this zoom
        'bottom tile row
        If App_Resolution = 96 Then
            BottomTileRow = Fix((Y_Pos - (100 * (1 + ZoomFactor))) / 10000) - Fix(StartBottom / 10000)
            If BottomTileRow < 0 Then BottomTileRow = 0
            'top tile row
            TopTileRow = Fix((Y_Pos + (100 * (1 + ZoomFactor))) / 10000) - Fix(StartBottom / 10000)
            If TopTileRow < 0 Then TopTileRow = 0
            If TopTileRow > 99 Then TopTileRow = 99
            'left tile row
            LeftTileRow = Fix((X_Pos - (100 * (1 + ZoomFactor))) / 10000) - Fix(StartLeft / 10000)
            If LeftTileRow < 0 Then LeftTileRow = 0
            'right tile row
            RightTileRow = Fix((X_Pos + (100 * (1 + ZoomFactor))) / 10000) - Fix(StartLeft / 10000)
            If RightTileRow < 0 Then RightTileRow = 0
            If RightTileRow > 99 Then RightTileRow = 99
        ElseIf App_Resolution = 192 Then
            BottomTileRow = Fix((Y_Pos - (272 * (1 + ZoomFactor))) / 10000) - Fix(StartBottom / 10000)
            If BottomTileRow < 0 Then BottomTileRow = 0
            'top tile row
            TopTileRow = Fix((Y_Pos + (272 * (1 + ZoomFactor))) / 10000) - Fix(StartBottom / 10000)
            If TopTileRow < 0 Then TopTileRow = 0
            If TopTileRow > 99 Then TopTileRow = 99
            'left tile row
            LeftTileRow = Fix((X_Pos - (388 * (1 + ZoomFactor))) / 10000) - Fix(StartLeft / 10000)
            If LeftTileRow < 0 Then LeftTileRow = 0
            'right tile row
            RightTileRow = Fix((X_Pos + (388 * (1 + ZoomFactor))) / 10000) - Fix(StartLeft / 10000)
            If RightTileRow < 0 Then RightTileRow = 0
            If RightTileRow > 99 Then RightTileRow = 99
        End If

        'Now we get ready to draw each tile within the zoom area
        Dim SC_Graphics As Graphics
        Dim SC_Pen As Pen
        Dim SC_Brush As SolidBrush

        SC_Graphics = Graphics.FromImage(SC_BitMap)
        If Session("Background") = "Landbase" Then
            SC_Graphics.FillRectangle(Brushes.Black, 0, 0, 776, 544)
        End If

        Dim TileNum As Integer, FirstPointRec As Integer, NumOfPoints As Integer, ObjType As Integer, LineWidth As Integer
        Dim it As Integer, iter As Integer
        Dim pIndex As Integer
        Dim SC_Color As Color
        Dim FirstX As Single, FirstY As Single, LastX As Single, LastY As Single
        Dim X_Factor As Integer
        Dim Y_Factor As Integer
        Dim SC_ColorAsLong As Integer, red As Integer, green As Integer, blue As Integer
        Dim lineMaxX As Integer, lineMaxY As Integer, lineMinX As Integer, lineMinY As Integer
        Dim circMaxX As Integer, circMaxY As Integer, circMinX As Integer, circMinY As Integer
        Dim outOfBox As Boolean, HeightPercent As Double

        If App_Resolution = 96 Then
            X_Factor = X_Pos - (100 * (1 + ZoomFactor))
            Y_Factor = Y_Pos - (100 * (1 + ZoomFactor))

            maxX = X_Pos + (100 * (1 + ZoomFactor))
            maxY = Y_Pos + (100 * (1 + ZoomFactor))
            minX = X_Pos - (100 * (1 + ZoomFactor))
            minY = Y_Pos - (100 * (1 + ZoomFactor))
        ElseIf App_Resolution = 192 Then
            X_Factor = X_Pos - (388 * (1 + ZoomFactor))
            Y_Factor = Y_Pos - (272 * (1 + ZoomFactor))

            maxX = X_Pos + (388 * (1 + ZoomFactor))
            maxY = Y_Pos + (272 * (1 + ZoomFactor))
            minX = X_Pos - (388 * (1 + ZoomFactor))
            minY = Y_Pos - (272 * (1 + ZoomFactor))
        End If


        'loop through each tile in the zoom area
        For TILENUMX = LeftTileRow To RightTileRow
            For TILENUMy = BottomTileRow To TopTileRow
                'do your stuff
                TileNum = (TILENUMX * 100) + TILENUMy

                For it = PlineTileIndexStart(TileNum) To PlineTileIndexStop(TileNum)
                    If fsRecIdx.Position <> ((it) * 4) Then
                        fsRecIdx.Seek(((it) * 4), SeekOrigin.Begin)
                    End If
                    If fsRecIdx.Position < fsRecIdx.Length Then
                        pIndex = brRecIdx.ReadInt32()


                        If fsPlines.Position <> ((pIndex) * 74) Then
                            fsPlines.Seek(((pIndex) * 74), SeekOrigin.Begin)
                        End If

                        ObjType = 0
                        handle = brPlines.ReadInt32()
                        LayerIndex = brPlines.ReadInt32()

                        SC_ColorAsLong = LayerArray(LayerIndex).Color

                        If LayerArray(LayerIndex).isOn = True And ((Trim(LayerArray(LayerIndex).LyrName) <> "Road" And Trim(LayerArray(LayerIndex).LyrName) <> "Roads" And Trim(LayerArray(LayerIndex).LyrName) <> "Roads1" And Trim(LayerArray(LayerIndex).LyrName) <> "Roads2" And Trim(LayerArray(LayerIndex).LyrName) <> "Roads3" And Trim(LayerArray(LayerIndex).LyrName) <> "Water" And Trim(LayerArray(LayerIndex).LyrName) <> "Rd_dirt" And Trim(LayerArray(LayerIndex).LyrName) <> "Rd_dirt_drive" And Trim(LayerArray(LayerIndex).LyrName) <> "Rd_dirt_lane" And Trim(LayerArray(LayerIndex).LyrName) <> "Rd_dirt_lane_drive" And Trim(LayerArray(LayerIndex).LyrName) <> "Rd_interstate" And Trim(LayerArray(LayerIndex).LyrName) <> "Rd_paved" And Trim(LayerArray(LayerIndex).LyrName) <> "Rd_paved_drive" And Trim(LayerArray(LayerIndex).LyrName) <> "Rd_paved_lane" And Trim(LayerArray(LayerIndex).LyrName) <> "Rd_paved_lane_drive") Or Session("Background") = "Landbase") Then
                            red = SC_ColorAsLong Mod &H100  'get red component
                            SC_ColorAsLong = SC_ColorAsLong \ &H100  'divide
                            green = SC_ColorAsLong Mod &H100 'get green component
                            SC_ColorAsLong = SC_ColorAsLong \ &H100  'divide
                            blue = SC_ColorAsLong Mod &H100 'get blue component

                            SC_Color = Color.FromArgb(red, green, blue)

                            SC_Pen = New System.Drawing.Pen(SC_Color)
                            SC_Brush = New SolidBrush(SC_Color)

                            If ObjType = 0 Then

                                Visible = brPlines.ReadInt32
                                LineWidth = brPlines.ReadInt32
                                NumOfPoints = brPlines.ReadInt32
                                FirstPointRec = brPlines.ReadInt32
                                lineMinX = brPlines.ReadInt32
                                lineMinY = brPlines.ReadInt32
                                lineMaxX = brPlines.ReadInt32
                                lineMaxY = brPlines.ReadInt32

                                SC_Pen.Width = ((LineWidth / 100) / (1 + ZoomFactor))

                                outOfBox = False
                                If maxX < lineMinX Or minX > lineMaxX Then outOfBox = True
                                If maxY < lineMinY Or minY > lineMaxY Then outOfBox = True
                                If outOfBox = False And Visible = -1 Then

                                    If fsPlinePoints.Position <> ((FirstPointRec) * 8) Then
                                        fsPlinePoints.Seek((FirstPointRec) * 8, SeekOrigin.Begin)
                                    End If

                                    FirstX = brPlinePoints.ReadInt32
                                    FirstY = brPlinePoints.ReadInt32

                                    FirstX = ((FirstX - X_Factor) / (1 + ZoomFactor))
                                    FirstY = ((FirstY - Y_Factor) / (1 + ZoomFactor))

                                    If App_Resolution = 96 Then
                                        FirstY = ((FirstY - 100) * -2) + FirstY  'FLIP THE Y NOT THE X
                                    ElseIf App_Resolution = 192 Then
                                        FirstY = ((FirstY - 272) * -2) + FirstY  'FLIP THE Y NOT THE X
                                    End If

                                    Dim SC_Path As New System.Drawing.Drawing2D.GraphicsPath

                                    For iter = FirstPointRec + 1 To FirstPointRec + NumOfPoints - 1
                                        LastX = brPlinePoints.ReadInt32
                                        LastY = brPlinePoints.ReadInt32
                                        LastX = ((LastX - X_Factor) / (1 + ZoomFactor))
                                        LastY = ((LastY - Y_Factor) / (1 + ZoomFactor))

                                        If App_Resolution = 96 Then
                                            LastY = ((LastY - 100) * -2) + LastY ' FLIP THE Y NOT THE X
                                        ElseIf App_Resolution = 192 Then
                                            LastY = ((LastY - 272) * -2) + LastY ' FLIP THE Y NOT THE X
                                        End If

                                        SC_Path.AddLine(FirstX, FirstY, LastX, LastY)

                                        FirstX = LastX
                                        FirstY = LastY
                                    Next

                                    SC_Graphics.DrawPath(SC_Pen, SC_Path)

                                End If

                            End If
                            SC_Pen.Dispose()
                            SC_Brush.Dispose()
                        End If
                    End If
                Next

                'Blocks
                If ZoomFactor < 12 Then



                    For it = BlockTileIndexStart(TileNum) To BlockTileIndexStop(TileNum)
                        If fsBlockRecIdx.Position <> ((it) * 4) Then
                            fsBlockRecIdx.Seek(((it) * 4), SeekOrigin.Begin)
                        End If
                        If fsBlockRecIdx.Position < fsBlockRecIdx.Length Then
                            pIndex = brBlockRecIdx.ReadInt32()

                            If fsBlockRefs.Position <> ((pIndex) * 32) Then
                                fsBlockRefs.Seek(((pIndex) * 32), SeekOrigin.Begin)
                            End If

                            handle = brBlockRefs.ReadInt32()
                            unUsed = brBlockRefs.ReadInt16()
                            unUsed = brBlockRefs.ReadInt16()
                            InsertX = brBlockRefs.ReadInt32()
                            InsertY = brBlockRefs.ReadInt32()
                            LayerIndex = brBlockRefs.ReadInt16()
                            OwnerId = brBlockRefs.ReadInt32()
                            Rotation = brBlockRefs.ReadInt32()
                            ScaleFactor = brBlockRefs.ReadInt16()
                            Visible = brBlockRefs.ReadInt16()

                            BlkRotation = Rotation / 100

                            SC_ColorAsLong = LayerArray(LayerIndex).Color

                            If LayerArray(LayerIndex).isOn = True And Trim(LayerArray(LayerIndex).LyrName) <> "Fieldchk_pfp" And Trim(LayerArray(LayerIndex).LyrName) <> "Fieldchk_sfp" Then

                                red = SC_ColorAsLong Mod &H100  'get red component
                                SC_ColorAsLong = SC_ColorAsLong \ &H100  'divide
                                green = SC_ColorAsLong Mod &H100 'get green component
                                SC_ColorAsLong = SC_ColorAsLong \ &H100  'divide
                                blue = SC_ColorAsLong Mod &H100 'get blue component

                                SC_Color = Color.FromArgb(red, green, blue)

                                SC_Pen = New System.Drawing.Pen(SC_Color)
                                SC_Brush = New SolidBrush(SC_Color)


                                If fsBlkMetaTileIdx.Position <> ((OwnerId) * 8) Then
                                    fsBlkMetaTileIdx.Seek(((OwnerId) * 8), SeekOrigin.Begin)
                                End If

                                recStart = recStart

                                recStart = brBlkMetaTileIdx.ReadInt32()
                                recStop = brBlkMetaTileIdx.ReadInt32()

                                For i = recStart To recStop
                                    If fsBlkPlines.Position <> ((i) * 36) Then
                                        fsBlkPlines.Seek(((i) * 36), SeekOrigin.Begin)
                                    End If

                                    ObjType = brBlkPlines.ReadInt32()
                                    unUsed = brBlkPlines.ReadInt32()
                                    FirstPointRec = brBlkPlines.ReadInt32
                                    NumOfPoints = brBlkPlines.ReadInt32
                                    LineWidth = brBlkPlines.ReadInt32
                                    lineMaxX = brBlkPlines.ReadInt32 + InsertX
                                    lineMaxY = brBlkPlines.ReadInt32 + InsertY
                                    lineMinX = brBlkPlines.ReadInt32 + InsertX
                                    lineMinY = brBlkPlines.ReadInt32 + InsertY

                                    If ObjType = 0 Then

                                        SC_Pen.Width = ((LineWidth / 100) / (1 + ZoomFactor))

                                        outOfBox = False
                                        If maxX < lineMinX Or minX > lineMaxX Then outOfBox = True
                                        If maxY < lineMinY Or minY > lineMaxY Then outOfBox = True
                                        If outOfBox = False And Visible = -1 Then

                                            If fsBlkPlinePoints.Position <> ((FirstPointRec) * 8) Then
                                                fsBlkPlinePoints.Seek((FirstPointRec) * 8, SeekOrigin.Begin)
                                            End If

                                            FirstX = brBlkPlinePoints.ReadInt32
                                            FirstY = brBlkPlinePoints.ReadInt32

                                            NewX = (FirstX * Cos(BlkRotation)) - (FirstY * Sin(BlkRotation))
                                            NewY = (FirstX * Sin(BlkRotation)) + (FirstY * Cos(BlkRotation))
                                            FirstX = NewX + InsertX
                                            FirstY = NewY + InsertY

                                            FirstX = ((FirstX - X_Factor) / (1 + ZoomFactor))
                                            FirstY = ((FirstY - Y_Factor) / (1 + ZoomFactor))

                                            If App_Resolution = 96 Then
                                                FirstY = ((FirstY - 100) * -2) + FirstY  'FLIP THE Y NOT THE X
                                            ElseIf App_Resolution = 192 Then
                                                FirstY = ((FirstY - 272) * -2) + FirstY  'FLIP THE Y NOT THE X
                                            End If


                                            For iter = FirstPointRec + 1 To FirstPointRec + NumOfPoints - 1
                                                LastX = brBlkPlinePoints.ReadInt32
                                                LastY = brBlkPlinePoints.ReadInt32

                                                NewX = (LastX * Cos(BlkRotation)) - (LastY * Sin(BlkRotation))
                                                NewY = (LastX * Sin(BlkRotation)) + (LastY * Cos(BlkRotation))
                                                LastX = NewX + InsertX
                                                LastY = NewY + InsertY

                                                LastX = ((LastX - X_Factor) / (1 + ZoomFactor))
                                                LastY = ((LastY - Y_Factor) / (1 + ZoomFactor))

                                                If App_Resolution = 96 Then
                                                    LastY = ((LastY - 100) * -2) + LastY ' FLIP THE Y NOT THE X
                                                ElseIf App_Resolution = 192 Then
                                                    LastY = ((LastY - 272) * -2) + LastY ' FLIP THE Y NOT THE X
                                                End If

                                                SC_Graphics.DrawLine(SC_Pen, FirstX, FirstY, LastX, LastY)

                                                FirstX = LastX
                                                FirstY = LastY
                                            Next

                                        End If
                                    ElseIf ObjType = 1 Then
                                        Dim X As Single, Y As Single, R As Single

                                        X = FirstPointRec
                                        Y = NumOfPoints

                                        NewX = (X * Cos(BlkRotation)) - (Y * Sin(BlkRotation))
                                        NewY = (X * Sin(BlkRotation)) + (Y * Cos(BlkRotation))
                                        X = NewX + InsertX
                                        Y = NewY + InsertY

                                        R = LineWidth

                                        circMaxX = lineMaxX
                                        circMaxY = lineMaxY
                                        circMinX = lineMinX
                                        circMinY = lineMinY
                                        outOfBox = False
                                        If maxX < circMinX Or minX > circMaxX Then outOfBox = True
                                        If maxY < circMinY Or minY > circMaxY Then outOfBox = True
                                        If outOfBox = False Then
                                            X = ((X - X_Factor) / (1 + ZoomFactor))
                                            Y = ((Y - Y_Factor) / (1 + ZoomFactor))

                                            If App_Resolution = 96 Then
                                                Y = ((Y - 100) * -2) + Y  'FLIP THE Y NOT THE X
                                            ElseIf App_Resolution = 192 Then
                                                Y = ((Y - 272) * -2) + Y  'FLIP THE Y NOT THE X
                                            End If

                                            R = (R / (1 + ZoomFactor))
                                            X = X - R
                                            Y = Y - R
                                            SC_Graphics.DrawEllipse(SC_Pen, X, Y, 2 * R, 2 * R)
                                        End If
                                    ElseIf ObjType = -5 Then    'Simple Text for Blocks
                                        If fsBlkText.Position <> ((FirstPointRec) * 46) Then
                                            fsBlkText.Seek(((FirstPointRec) * 46), SeekOrigin.Begin)
                                        End If
                                        Dim BlkText As String
                                        Dim BlkTextHeight As Integer
                                        Dim BlkTextRotation As Double
                                        Dim BlkTextX As Integer
                                        Dim BlkTextY As Integer
                                        Dim X As Single, Y As Single



                                        BlkText = brBlkText.ReadChars(30)
                                        BlkTextX = brBlkText.ReadInt32()
                                        BlkTextY = brBlkText.ReadInt32()
                                        Rotation = brBlkText.ReadInt32()
                                        BlkTextHeight = brBlkText.ReadInt32()
                                        BlkTextRotation = Rotation / 100


                                        X = BlkTextX - ((BlkTextHeight - (2 * BlkTextHeight / 3)) * Cos(BlkTextRotation))

                                        Y = BlkTextY + ((BlkTextHeight - (2 * BlkTextHeight / 3)) * Sin(BlkTextRotation))

                                        NewX = (X * Cos(BlkRotation)) - (Y * Sin(BlkRotation))
                                        NewY = (X * Sin(BlkRotation)) + (Y * Cos(BlkRotation))
                                        X = NewX + InsertX
                                        Y = NewY + InsertY

                                        BlkTextRotation = BlkTextRotation + BlkRotation

                                        X = X - ((BlkTextHeight + (BlkTextHeight / 3)) * Sin(BlkTextRotation))

                                        Y = Y + ((BlkTextHeight + (BlkTextHeight / 3)) * Cos(BlkTextRotation))


                                        X = ((X - X_Factor) / (1 + ZoomFactor))
                                        Y = ((Y - Y_Factor) / (1 + ZoomFactor))

                                        If App_Resolution = 96 Then
                                            Y = ((Y - 100) * -2) + Y  'FLIP THE Y NOT THE X
                                        ElseIf App_Resolution = 192 Then
                                            Y = ((Y - 272) * -2) + Y  'FLIP THE Y NOT THE X
                                        End If

                                        BlkTextHeight = ((BlkTextHeight) / (1 + ZoomFactor))

                                        If BlkTextHeight <> 0 Then
                                            Dim scFont As New Font("RomanD", BlkTextHeight, FontStyle.Regular)
                                            SC_Graphics.TranslateTransform(X, Y)
                                            SC_Graphics.RotateTransform(-(BlkTextRotation * 180 \ PI))

                                            SC_Graphics.DrawString(Trim(BlkText), scFont, SC_Brush, 0, 0)
                                            SC_Graphics.ResetTransform()
                                        End If

                                    End If
                                Next

Next_Block:
                                SC_Pen.Dispose()
                                SC_Brush.Dispose()
                            End If
                        End If
                    Next


                    Dim Height As Integer
                    Dim Halign As Integer
                    Dim TextString As String
                    Dim Valign As Integer
                    Dim AttRotation As Single
                    Dim H As Single

                    For it = AttTileIndexStart(TileNum) To AttTileIndexStop(TileNum)
                        If fsAttRecIdx.Position <> ((it) * 4) Then
                            fsAttRecIdx.Seek(((it) * 4), SeekOrigin.Begin)
                        End If
                        If fsAttRecIdx.Position < fsAttRecIdx.Length Then
                            pIndex = brAttRecIdx.ReadInt32()

                            If fsAttRefs.Position <> ((pIndex) * 84) Then
                                fsAttRefs.Seek(((pIndex) * 84), SeekOrigin.Begin)
                            End If

                            handle = brAttRefs.ReadInt32()
                            Height = brAttRefs.ReadInt16()
                            Halign = brAttRefs.ReadInt16()
                            InsertX = brAttRefs.ReadInt32()
                            InsertY = brAttRefs.ReadInt32()
                            LayerIndex = brAttRefs.ReadInt16()
                            OwnerId = brAttRefs.ReadInt32()
                            Rotation = brAttRefs.ReadInt32()
                            ScaleFactor = brAttRefs.ReadInt16()
                            unUsed = brAttRefs.ReadInt16()
                            TextString = brAttRefs.ReadChars(50)
                            Valign = brAttRefs.ReadInt16()
                            Visible = brAttRefs.ReadInt16()

                            AttRotation = Rotation / 100
                            H = Height

                            SC_ColorAsLong = LayerArray(LayerIndex).Color

                            If LayerArray(LayerIndex).isOn = True Then

                                red = SC_ColorAsLong Mod &H100  'get red component
                                SC_ColorAsLong = SC_ColorAsLong \ &H100  'divide
                                green = SC_ColorAsLong Mod &H100 'get green component
                                SC_ColorAsLong = SC_ColorAsLong \ &H100  'divide
                                blue = SC_ColorAsLong Mod &H100 'get blue component

                                SC_Color = Color.FromArgb(red, green, blue)

                                SC_Pen = New System.Drawing.Pen(SC_Color)
                                SC_Brush = New SolidBrush(SC_Color)

                                InsertX = InsertX - ((H + (H / 3)) * Sin(AttRotation))

                                InsertY = InsertY + ((H + (H / 3)) * Cos(AttRotation))


                                InsertX = ((InsertX - X_Factor) / (1 + ZoomFactor))
                                InsertY = ((InsertY - Y_Factor) / (1 + ZoomFactor))

                                If App_Resolution = 96 Then
                                    InsertY = ((InsertY - 100) * -2) + InsertY  'FLIP THE Y NOT THE X
                                ElseIf App_Resolution = 192 Then
                                    InsertY = ((InsertY - 272) * -2) + InsertY  'FLIP THE Y NOT THE X
                                End If

                                H = ((H) / (1 + ZoomFactor))

                                If Trim(TextString) = "36892" Or Trim(TextString) = "36895" Then
                                    TextString = TextString
                                End If
                                If H > 0 Then
                                    Dim scFont As New Font("RomanD", H, FontStyle.Regular)
                                    SC_Graphics.TranslateTransform(InsertX, InsertY)
                                    SC_Graphics.RotateTransform(-(AttRotation * 180 \ PI))

                                    SC_Graphics.DrawString(Trim(TextString), scFont, SC_Brush, 0, 0)
                                    SC_Graphics.ResetTransform()
                                End If

                                SC_Pen.Dispose()
                                SC_Brush.Dispose()
                            End If
                        End If
                    Next
                End If

            Next TILENUMy
        Next TILENUMX
        fsPlines.Close()
        brPlines.Close()
        fsPlinePoints.Close()
        brPlinePoints.Close()
        fsRecIdx.Close()
        brRecIdx.Close()

        brBlockRefs.Close()
        brBlockRecIdx.Close()
        brAttRefs.Close()
        brAttRecIdx.Close()
        brBlkMetaTileIdx.Close()
        brBlkPlines.Close()
        brBlkPlinePoints.Close()
        fsBlockRefs.Close()
        fsBlockRecIdx.Close()
        fsAttRefs.Close()
        fsAttRecIdx.Close()
        fsBlkMetaTileIdx.Close()
        fsBlkPlines.Close()
        fsBlkPlinePoints.Close()
        fsBlkText.Close()
        brBlkText.Close()


        fsPlines = Nothing
        brPlines = Nothing
        fsPlinePoints = Nothing
        brPlinePoints = Nothing
        fsRecIdx = Nothing
        brRecIdx = Nothing

        brBlockRefs = Nothing
        brBlockRecIdx = Nothing
        brAttRefs = Nothing
        brAttRecIdx = Nothing
        brLyrArray = Nothing
        brBlkMetaTileIdx = Nothing
        brBlkPlines = Nothing
        brBlkPlinePoints = Nothing
        fsBlockRefs = Nothing
        fsBlockRecIdx = Nothing
        fsAttRefs = Nothing
        fsAttRecIdx = Nothing
        fsLyrArray = Nothing
        fsBlkMetaTileIdx = Nothing
        fsBlkPlines = Nothing
        fsBlkPlinePoints = Nothing
        fsBlkText = Nothing
        brBlkText = Nothing


        'Draw the Cross in the center of the screen
        SC_Color = Color.WhiteSmoke
        SC_Pen = New System.Drawing.Pen(SC_Color)

        If App_Resolution = 96 Then
            SC_Graphics.DrawLine(SC_Pen, 100, 99, 100, 101)
            SC_Graphics.DrawLine(SC_Pen, 99, 100, 101, 100)
        ElseIf App_Resolution = 192 Then
            SC_Graphics.DrawLine(SC_Pen, 388, 269, 388, 275)
            SC_Graphics.DrawLine(SC_Pen, 385, 272, 391, 272)
        End If

        SC_Pen.Dispose()

    End Sub