Public Class frmCutSelectedSheet
Dim GraphicsFun As System.Drawing.Graphics
Dim PenColor As New System.Drawing.Pen(Color.Red)
Private lines As New List(Of Line)
Dim start As Point
Dim [end] As Point
Dim counter As Integer = 0
Dim Coordinates As String
Dim NumberOfCuts As Integer
Private Sub frmCutSelectedSheet_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Place a blank image in the PictureBox control.
Me.pctPaintBox.Image = New Bitmap(Me.pctPaintBox.Width, Me.pctPaintBox.Height)
lblStartingX.Text = "<= " & Me.pctPaintBox.Width - 1
lblStartingY.Text = "<= " & Me.pctPaintBox.Height - 1
lblEndingX.Text = "<= " & Me.pctPaintBox.Width - 1
lblEndingY.Text = "<= " & Me.pctPaintBox.Height - 1
Me.txtStartingX.Enabled = False
Me.txtStartingY.Enabled = False
Me.txtEndingX.Enabled = False
Me.txtEndingY.Enabled = False
End Sub
Private Sub pctPaintBox_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pctPaintBox.Paint
'Draw each line on the control.
For Each line As Line In Me.lines
e.Graphics.DrawLine(Pens.Black, line.Start, line.End)
Next line
End Sub
Private Sub Save()
'Create a Graphics object from the Image in the PictureBox.
Dim g As Graphics = Graphics.FromImage(Me.pctPaintBox.Image)
'Draw each line on the image to make them permanent.
For Each line As Line In Me.lines
g.DrawLine(Pens.Black, line.Start, line.End)
Next line
'Clear the temporary lines that were just saved.
Me.Clear()
End Sub
Private Sub Clear()
'Clear all unsaved lines.
Me.lines.Clear()
'Force the control to repaint so the lines are removed.
Me.pctPaintBox.Refresh()
End Sub
Private Sub btnNextCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextCut.Click
If counter = 0 Then
Me.txtStartingX.Enabled = True
Me.txtStartingY.Enabled = True
Me.txtEndingX.Enabled = True
Me.txtEndingY.Enabled = True
counter += 1
Else
Call Me.Clear()
With Me.pctPaintBox
If txtStartingX.Text >= .Width Then
MsgBox("X coordinate startpoint is invalid")
Exit Sub
ElseIf txtStartingY.Text >= .Height Then
MsgBox("Y coordinate startpoint is invalid")
Exit Sub
ElseIf txtEndingX.Text >= .Width Then
MsgBox("X coordinate endingpoint is invalid")
Exit Sub
ElseIf txtEndingY.Text >= .Height Then
MsgBox("Y coordinate endingpoint is invalid")
Exit Sub
Else
[end] = New Point(txtEndingX.Text, txtEndingY.Text)
start = New Point(txtStartingX.Text, txtStartingY.Text)
'Add the new line to the list.
Me.lines.Add(New Line(Me.start, [end]))
'Force the control to repaint so the new line is drawn.
Me.pctPaintBox.Invalidate(New Rectangle(Math.Min(Me.start.X, [end].X), _
Math.Min(Me.start.Y, [end].Y), _
Math.Abs(Me.start.X - [end].X), _
Math.Abs(Me.start.Y - [end].Y)))
'Me.Refresh()
Call Me.Save()
If Coordinates = "" Then
Coordinates = "(" & txtStartingX.Text & "," & txtStartingY.Text & "," & txtEndingX.Text & "," & txtEndingY.Text & ")"
Else
Coordinates = Coordinates & "#" & "(" & txtStartingX.Text & "," & txtStartingY.Text & "," & txtEndingX.Text & "," & txtEndingY.Text & ")"
End If
txtStartingX.Text = ""
txtStartingY.Text = ""
txtEndingX.Text = ""
txtEndingY.Text = ""
lblCuts.Text = "Cuts : " & Me.lines.Count
counter += 1
End If
End With
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
End Sub
End Class
Public Class Line
'The line's start point.
Private _start As Point
'The line's end point.
Private _end As Point
'The line's start point.
Public Property Start() As Point
Get
Return Me._start
End Get
Set(ByVal value As Point)
Me._start = value
End Set
End Property
'The line's end point.
Public Property [End]() As Point
Get
Return Me._end
End Get
Set(ByVal value As Point)
Me._end = value
End Set
End Property
Public Sub New()
Me.New(Point.Empty, Point.Empty)
End Sub
Public Sub New(ByVal start As Point, ByVal [end] As Point)
Me._start = start
Me._end = [end]
End Sub
End Class