bluecommand.vb

来自「《ViSUAL BASIC》设计模式」· VB 代码 · 共 68 行

VB
68
字号
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Color
Imports System.WinForms
Imports System.Collections

public class BlueCommand
  Implements Command

Private drawList As ArrayList
Protected colr as Color
Protected x, y , dx, dy As Integer
Private pic As PictureBox
    '-----
    Public Sub New(ByVal pict As PictureBox)
        MyBase.New()
        pic = pict
        drawList = New ArrayList()
        x = pic.Width
        Colr = color.Blue
        dx = -20
        y = 0
        dy = 0
    End Sub
    '-----
    Public Sub Execute() Implements Command.Execute
        Dim dl As DrawData
        dl = New DrawData(x, y, dx, dy)
        drawList.add(dl)
        x = x + dx
        y = y + dy
        pic.Refresh()
    End Sub
    '-----
    Public Function isUndo() As Boolean Implements Command.IsUndo
        Return False
    End Function
    '-----
    Public Sub Undo() Implements Command.Undo
        Dim Index As Integer
        Dim dl As DrawData
        Index = drawList.Count - 1
        If Index >= 0 Then
            dl = CType(drawList(index), DrawData)
            drawList.RemoveAt(Index)
            x = dl.getX
            y = dl.getY
        End If
        pic.Refresh()
    End Sub
    '-----
    Public Sub draw(ByVal g As Graphics)
        Dim h, w As Integer
        Dim i As Integer
        Dim dl As DrawData
        
        Dim rpen As New Pen(Color.FromARGB(255, colr), 1)
        h = pic.Height
        w = pic.Width
        
        For i = 0 To drawList.Count - 1
            dl = CType(drawList(i), DrawData)
            g.drawLine(rpen, dl.getX, dl.getY, dl.getX + dx, dl.getdY + h)
        Next i
    End Sub
End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?