Draw lines on panel

This commit is contained in:
Anton 2021-01-25 11:15:21 +01:00
parent ad8dc6f6dc
commit 5921ba4b84
2 changed files with 25 additions and 47 deletions

View File

@ -23,30 +23,30 @@ Partial Class GUI
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(GUI))
Me.Panel1 = New System.Windows.Forms.Panel()
Me.DrawingPanel = New System.Windows.Forms.Panel()
Me.SuspendLayout()
'
'Panel1
'DrawingPanel
'
Me.Panel1.BackColor = System.Drawing.SystemColors.ControlLight
Me.Panel1.Location = New System.Drawing.Point(702, 152)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(610, 388)
Me.Panel1.TabIndex = 0
Me.DrawingPanel.BackColor = System.Drawing.SystemColors.ActiveCaption
Me.DrawingPanel.Location = New System.Drawing.Point(277, 138)
Me.DrawingPanel.Name = "DrawingPanel"
Me.DrawingPanel.Size = New System.Drawing.Size(751, 339)
Me.DrawingPanel.TabIndex = 0
'
'GUI
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(1324, 552)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.DrawingPanel)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)
Me.Margin = New System.Windows.Forms.Padding(4)
Me.Name = "GUI"
Me.Text = "Build a wardrobe"
Me.ResumeLayout(False)
End Sub
Friend WithEvents Panel1 As Panel
Friend WithEvents DrawingPanel As Panel
End Class

View File

@ -1,52 +1,30 @@
Imports XCCLibrary
Public Class GUI
Public Shared Surface As Graphics
Public Shared line As Integer = 0
Public Shared point1 As Integer = 0
Public Shared point2 As Integer = 0
Public Shared point1p
Public Shared point2p
Public Shared mpos
Sub GUI_load() Handles MyBase.Load
Surface = CreateGraphics()
get_drawbox()
Dim DrawBox As Panel
Dim boxX, boxY, boxW, boxH, boxMidX, boxMidY As Integer
Sub GUI_load() Handles MyBase.Load
DrawBox = DrawingPanel
AddHandler DrawBox.Paint, AddressOf DrawingPanel_Paint
get_drawboxParameters()
End Sub
Private Sub get_drawbox()
Dim DrawBox As Panel
DrawBox = Panel1
Private Sub get_drawboxParameters()
boxX = DrawBox.Location.X
boxY = DrawBox.Location.Y
Dim locX, locY As Integer
locX = DrawBox.Location.X
locY = DrawBox.Location.Y
Dim boxW, boxH As Integer
boxW = DrawBox.Size.Width
boxH = DrawBox.Size.Height
Dim boxMidX, boxMidY As Integer
boxMidX = locX + boxW / 2
boxMidY = locY + boxH / 2
boxMidX = boxX + boxW / 2
boxMidY = boxY + boxH / 2
End Sub
Private Sub DrawingPanel_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs)
Dim pen As Pen = New Pen(Color.Red, 2)
Surface.DrawLine(pen, boxMidX, boxMidY, locX, locY)
e.Graphics.DrawLine(pen, boxMidX, boxMidY, boxMidX + 1, boxMidY + 1)
End Sub
Private Sub mouse_cl(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
mpos = e
If point1 = 0 And point2 = 0 Then
point1p = mpos
point1 = 1
ElseIf point1 = 1 And point2 = 0 Then
point2p = mpos
point2 = 1
Dim pen1 As Pen = New Pen(Color.Red, 2)
Surface.DrawLine(pen1, point1p.X, point1p.Y, point2p.X, point2p.Y)
point1 = 0
point2 = 0
End If
End Sub
End Class