Imports System.Reflection

Public Class frmDesigner

#Region " Variables "
    ' Define sizes for Centre squares and walls.
    Private Const wallThickness As Integer = 20 ' The base wall thickness.
    Private CentreSquareSize As Integer = CInt(wallThickness * 0.7) ' Centre squares will be 70% of the original wall thickness.

    ' Variables for the flashing highlight.
    Private highlightOn As Boolean = False ' Keeps track of the on/off state of the flash.
    Private highlightedArea As Rectangle = Rectangle.Empty ' The area currently being highlighted.
#End Region

#Region " Load "
    Private Sub frmDesigner_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Enable double buffering on the PictureBox for smooth rendering.
        Utilities.EnableDoubleBuffering(picGame)

        ' Start the timer for the flashing highlight.
        timerHighlight.Enabled = True
    End Sub
#End Region

#Region " Paint "
    Private Sub PicGame_Paint(sender As Object, e As PaintEventArgs) Handles picGame.Paint
        Dim gap As Integer = 30 ' Gap on all sides (top, bottom, left, right).

        ' Get PictureBox effective dimensions, subtracting the gaps.
        Dim picWidth As Integer = picGame.Width - (2 * gap)
        Dim picHeight As Integer = picGame.Height - (2 * gap)

        ' Define rows and columns in the grid.
        Dim cols As Integer = 16
        Dim rows As Integer = 10

        ' Calculate cell width and height.
        Dim cellWidth As Integer = picWidth \ cols
        Dim cellHeight As Integer = picHeight \ rows

        ' Get the Graphics object from the Paint event.
        Dim g As Graphics = e.Graphics

        ' Create brushes for coloring different parts.
        Dim wallBrush As New SolidBrush(Color.Blue)
        Dim floorBrush As New SolidBrush(Color.Green)
        Dim segmentBrush As New SolidBrush(Color.Red)

        ' ---- Draw Floors (Green) ----
        For row As Integer = 0 To rows - 1
            For col As Integer = 0 To cols - 1
                ' Base coordinates of the cell (top-left corner of the cell).
                Dim x As Integer = gap + (col * cellWidth)
                Dim y As Integer = gap + (row * cellHeight)

                ' Calculate the floor area:
                Dim floorX As Integer = x + (CentreSquareSize \ 2)
                Dim floorY As Integer = y + (CentreSquareSize \ 2)
                Dim floorWidth As Integer = cellWidth - CentreSquareSize
                Dim floorHeight As Integer = cellHeight - CentreSquareSize

                ' Draw the green floor rectangle.
                g.FillRectangle(floorBrush, floorX, floorY, floorWidth, floorHeight)
            Next
        Next

        ' ---- Draw Horizontal Walls (Blue) ----
        For row As Integer = 0 To rows
            For col As Integer = 0 To cols - 1
                ' Base coordinates for horizontal walls.
                Dim x As Integer = gap + (col * cellWidth)
                Dim y As Integer = gap + (row * cellHeight)

                ' Horizontal wall starts at the right edge of a centre square and spans to the next Centre square.
                Dim wallX As Integer = x + (CentreSquareSize \ 2)
                Dim wallY As Integer = y - (CentreSquareSize \ 2)
                Dim wallWidth As Integer = cellWidth - CentreSquareSize

                ' Draw the horizontal wall (blue).
                g.FillRectangle(wallBrush, wallX, wallY, wallWidth, CentreSquareSize)
            Next
        Next

        ' ---- Draw Vertical Walls (Blue) ----
        For row As Integer = 0 To rows - 1
            For col As Integer = 0 To cols
                ' Base coordinates for vertical walls.
                Dim x As Integer = gap + (col * cellWidth)
                Dim y As Integer = gap + (row * cellHeight)

                ' Vertical wall starts at the bottom edge of a Centre square and spans to the next Centre square.
                Dim wallX As Integer = x - (CentreSquareSize \ 2)
                Dim wallY As Integer = y + (CentreSquareSize \ 2)
                Dim wallHeight As Integer = cellHeight - CentreSquareSize

                ' Draw the vertical wall (blue).
                g.FillRectangle(wallBrush, wallX, wallY, CentreSquareSize, wallHeight)
            Next
        Next

        ' ---- Draw Centre Segments (Corners) ----
        For row As Integer = 0 To rows
            For col As Integer = 0 To cols
                ' Centre squares' position aligned perfectly at grid intersections.
                Dim x As Integer = gap + (col * cellWidth) - (CentreSquareSize \ 2)
                Dim y As Integer = gap + (row * cellHeight) - (CentreSquareSize \ 2)

                ' Draw the Centre square at the intersection (corner).
                g.FillRectangle(segmentBrush, x, y, CentreSquareSize, CentreSquareSize)
            Next
        Next

        ' ---- Draw the Highlight (Flashing Jagged Outline) ----
        If Not highlightedArea.IsEmpty Then
            Dim highlightBrush As New SolidBrush(If(highlightOn, Color.Black, Color.White))
            Dim outlineSize As Integer = 5 ' Size of the jagged outline segments.

            ' Draw top jagged line.
            For i As Integer = 0 To highlightedArea.Width Step outlineSize * 2
                If i >= CentreSquareSize AndAlso i <= highlightedArea.Width - CentreSquareSize Then
                    g.FillRectangle(highlightBrush, highlightedArea.Left + i, highlightedArea.Top, outlineSize, outlineSize)
                End If
            Next

            ' Draw right jagged line.
            For i As Integer = 0 To highlightedArea.Height Step outlineSize * 2
                If i >= CentreSquareSize AndAlso i <= highlightedArea.Height - CentreSquareSize Then
                    g.FillRectangle(highlightBrush, highlightedArea.Right - outlineSize, highlightedArea.Top + i, outlineSize, outlineSize)
                End If
            Next

            ' Draw bottom jagged line.
            For i As Integer = 0 To highlightedArea.Width Step outlineSize * 2
                If i >= CentreSquareSize AndAlso i <= highlightedArea.Width - CentreSquareSize Then
                    g.FillRectangle(highlightBrush, highlightedArea.Left + i, highlightedArea.Bottom - outlineSize, outlineSize, outlineSize)
                End If
            Next

            ' Draw left jagged line.
            For i As Integer = 0 To highlightedArea.Height Step outlineSize * 2
                If i >= CentreSquareSize AndAlso i <= highlightedArea.Height - CentreSquareSize Then
                    g.FillRectangle(highlightBrush, highlightedArea.Left, highlightedArea.Top + i, outlineSize, outlineSize)
                End If
            Next

            highlightBrush.Dispose()
        End If

        ' Dispose of resources.
        wallBrush.Dispose()
        floorBrush.Dispose()
        segmentBrush.Dispose()
    End Sub
#End Region

#Region " Mouse "
    ' ---- MouseMove Implementation ----
    Private Sub PicGame_MouseMove(sender As Object, e As MouseEventArgs) Handles picGame.MouseMove
        Dim gap As Integer = 30 ' Gap around the grid.

        ' Define rows and columns.
        Dim cols As Integer = 16
        Dim rows As Integer = 10

        ' Get PictureBox effective dimensions, subtracting the gaps.
        Dim picWidth As Integer = picGame.Width - (2 * gap)
        Dim picHeight As Integer = picGame.Height - (2 * gap)

        ' Calculate cell width and height.
        Dim cellWidth As Integer = picWidth \ cols
        Dim cellHeight As Integer = picHeight \ rows

        ' Mouse coordinates relative to PictureBox.
        Dim mouseX As Integer = e.X
        Dim mouseY As Integer = e.Y

        ' Adjust the gap offset dynamically for wall alignment.
        Dim adjustedTopLeftX As Integer = gap - (CentreSquareSize \ 2)
        Dim adjustedTopLeftY As Integer = gap - (CentreSquareSize \ 2)

        ' Check if the mouse is within the grid area based on adjusted offsets.
        If mouseX >= adjustedTopLeftX AndAlso mouseX < picGame.Width - adjustedTopLeftX AndAlso
           mouseY >= adjustedTopLeftY AndAlso mouseY < picGame.Height - adjustedTopLeftY Then
            ' Map mouse position to grid coordinates.
            Dim gridCol As Integer = (mouseX - adjustedTopLeftX) \ cellWidth
            Dim gridRow As Integer = (mouseY - adjustedTopLeftY) \ cellHeight

            ' Calculate local position within the cell.
            Dim localX As Integer = (mouseX - adjustedTopLeftX) Mod cellWidth
            Dim localY As Integer = (mouseY - adjustedTopLeftY) Mod cellHeight

            ' Logic for determining the hoveCentre area.
            Dim newHighlight As Rectangle = Rectangle.Empty
            If localX < CentreSquareSize AndAlso localY < CentreSquareSize Then
                ' Mouse is over a Centre square (corner).
                stbGridCoords.Text = "-"
                newHighlight = New Rectangle(
                    adjustedTopLeftX + gridCol * cellWidth,
                    adjustedTopLeftY + gridRow * cellHeight,
                    CentreSquareSize, CentreSquareSize)
            ElseIf localY < CentreSquareSize Then
                ' Mouse is over a horizontal wall.
                stbGridCoords.Text = $"Horizontal Wall {gridCol},{gridRow}"
                newHighlight = New Rectangle(
                    adjustedTopLeftX + gridCol * cellWidth + CentreSquareSize,
                    adjustedTopLeftY + gridRow * cellHeight,
                    cellWidth - CentreSquareSize, CentreSquareSize)
            ElseIf localX < CentreSquareSize Then
                ' Mouse is over a vertical wall.
                stbGridCoords.Text = $"Vertical Wall {gridCol},{gridRow}"
                newHighlight = New Rectangle(
                    adjustedTopLeftX + gridCol * cellWidth,
                    adjustedTopLeftY + gridRow * cellHeight + CentreSquareSize,
                    CentreSquareSize, cellHeight - CentreSquareSize)
            Else
                ' Mouse is over a green floor.
                stbGridCoords.Text = $"Floor {gridRow},{gridCol}"
                newHighlight = New Rectangle(
                    adjustedTopLeftX + gridCol * cellWidth + CentreSquareSize,
                    adjustedTopLeftY + gridRow * cellHeight + CentreSquareSize,
                    cellWidth - CentreSquareSize, cellHeight - CentreSquareSize)
            End If

            ' Update the highlighted area if it changes.
            If newHighlight <> highlightedArea Then
                highlightedArea = newHighlight
                picGame.Invalidate() ' Redraw the grid to update the highlight.
            End If
        Else
            ' Mouse is outside the grid, clear the highlight.
            stbGridCoords.Text = "-"
            highlightedArea = Rectangle.Empty
            picGame.Invalidate()
        End If
    End Sub
#End Region
#Region " Timers "
    ' ---- Timer Tick for Flashing Highlight ----
    Private Sub TimerHighlight_Tick(sender As Object, e As EventArgs) Handles timerHighlight.Tick
        ' Toggle the highlight state and redraw the grid.
        highlightOn = Not highlightOn
        picGame.Invalidate()
    End Sub
#End Region

End Class

Can you fix this error
Unnecessary assignment of a value to 'newHighlight'

Also. Can you make sure the highlight is a square. ATM it's kinda circled. And doesn't fit properly