88 lines
2.5 KiB
VB.net
88 lines
2.5 KiB
VB.net
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_startPoints()
|
|
End Sub
|
|
|
|
Private Sub set_startPoints()
|
|
p1X = boxMidX - CInt(DrawW / 2)
|
|
p1Y = boxMidY - CInt(DrawH / 2)
|
|
p2X = boxMidX + CInt(DrawW / 2)
|
|
p2Y = boxMidY - CInt(DrawH / 2)
|
|
p3X = boxMidX + CInt(DrawW / 2)
|
|
p3Y = boxMidY + CInt(DrawH / 2)
|
|
p4X = boxMidX - CInt(DrawW / 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 - 30
|
|
DrawH = boxH - 30
|
|
|
|
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 Button1_Click(sender As Object, e As EventArgs) Handles Button1.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))
|
|
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))
|
|
End If
|
|
|
|
'Redraw rectangle
|
|
Me.Refresh()
|
|
End Sub
|
|
|
|
End Class
|