Imports System.Reflection Public Class frmDesigner #Region " Variables " ' Define sizes…
- User
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 - Assistant
- User
What's this error...
Public Function GetProjectDirectory() As String Dim dir As DirectoryInfo = New DirectoryInfo(Application.StartupPath) For i As Integer = 1 To 4 ' Adjust this number based on your directory structure If dir.Parent IsNot Nothing Then dir = dir.Parent End If Next Return dir.FullName End FunctionSeverity Code Description Project Project Rank Path File Line Column Category Source Suppression State Tool Message (active) IDE0140 Object creation can be simplified Enigma 1 D:\01 - Grags\Visual Studio\Enigma\Enigma D:\01 - Grags\Visual Studio\Enigma\Enigma\Utilities.vb 12 13 Style IntelliSense
- Assistant
The warning you're encountering, "Object creation can be simplified", indicates that the way you're creating the
DirectoryInfoobject can be streamlined.In your current code:
Dim dir As DirectoryInfo = New DirectoryInfo(Application.StartupPath)You can simplify the
Newkeyword usage for object instantiation since in VB.NET, the keyword is optional when creating an instance of a class. The code can instead simply be written as: