Imports XCCLibrary Public Class GUI Dim DrawBox As Panel Dim boxX, boxY, boxW, boxH, boxMidX, boxMidY As Integer Dim GratingW, GratingH As Double Dim DrawW, DrawH As Integer Dim Aspect1, Aspect2 As Double Dim p1X, p1Y, p2X, p2Y, p3X, p3Y, p4X, p4Y As Integer Sub GUI_load() Handles MyBase.Load DrawBox = DrawingPanel AddHandler DrawBox.Paint, AddressOf DrawingPanel_Paint get_drawboxParameters() set_startPointsX() set_startPointsY() End Sub Private Sub set_startPointsX() p1X = boxMidX - CInt(DrawW / 2) p2X = boxMidX + CInt(DrawW / 2) p3X = boxMidX + CInt(DrawW / 2) p4X = boxMidX - CInt(DrawW / 2) End Sub Private Sub set_startPointsY() p1Y = boxMidY - CInt(DrawH / 2) p2Y = boxMidY - CInt(DrawH / 2) p3Y = boxMidY + CInt(DrawH / 2) p4Y = boxMidY + CInt(DrawH / 2) End Sub Private Sub get_drawboxParameters() boxX = DrawBox.Location.X 'Behövs ej boxY = DrawBox.Location.Y 'Behövs ej boxW = DrawBox.Size.Width boxH = DrawBox.Size.Height boxMidX = boxW / 2 boxMidY = boxH / 2 DrawW = boxW - 50 DrawH = boxH - 50 Aspect1 = DrawW / DrawH End Sub Private Sub DrawingPanel_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Dim pen As Pen = New Pen(Color.Red, 2) e.Graphics.DrawLine(pen, p1X, p1Y, p2X, p2Y) e.Graphics.DrawLine(pen, p2X, p2Y, p3X, p3Y) e.Graphics.DrawLine(pen, p3X, p3Y, p4X, p4Y) e.Graphics.DrawLine(pen, p4X, p4Y, p1X, p1Y) End Sub Private Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateButton.Click GratingH = HeightBox.Text GratingW = WidthBox.Text Aspect2 = GratingW / GratingH If Aspect2 > Aspect1 Then 'Change draw height Dim wDiff As Double wDiff = GratingW / DrawW p1Y = boxMidY - CInt(GratingH / (wDiff * 2)) p2Y = boxMidY - CInt(GratingH / (wDiff * 2)) p3Y = boxMidY + CInt(GratingH / (wDiff * 2)) p4Y = boxMidY + CInt(GratingH / (wDiff * 2)) set_startPointsX() Else 'Change draw width Dim hDiff As Double hDiff = GratingH / DrawH p1X = boxMidX - CInt(GratingW / (hDiff * 2)) p2X = boxMidX + CInt(GratingW / (hDiff * 2)) p3X = boxMidX + CInt(GratingW / (hDiff * 2)) p4X = boxMidX - CInt(GratingW / (hDiff * 2)) set_startPointsY() End If 'Redraw rectangle Me.Refresh() End Sub Private Sub ExportSW_Click(sender As Object, e As EventArgs) Handles ExportSW.Click Program.Export_SW() End Sub End Class