Torna al Thread
Public Class FirmaBox
Inherits PictureBox
Dim OldCoord As Point
Dim MyBitMap As Bitmap
Dim brSize As Single
Dim myColor As System.Drawing.Color
Public Property ColoreInchiostro() As Color
Get
Return Me.myColor
End Get
Set(ByVal value As Color)
Me.myColor = value
End Set
End Property
Public Property DimensionePenna() As Single
Get
Return Me.brSize
End Get
Set(ByVal value As Single)
Me.brSize = value
End Set
End Property
Sub New()
AddHandler Me.MouseDown, AddressOf Me_MouseDown
AddHandler Me.MouseMove, AddressOf Me_MouseMove
AddHandler Me.HandleCreated, AddressOf Me_Load
Me.myColor = Color.Blue
Me.brSize = 5
End Sub
Sub Me_Load(ByVal sender As Object, ByVal e As EventArgs)
Me.MyBitMap = New Bitmap(Me.Width, Me.Height)
Me.Image = MyBitMap
End Sub
Private Sub Me_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
OldCoord = New Point(e.Location)
End If
End Sub
Private Sub Me_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim myPen As System.Drawing.Pen = New Pen(myColor, brSize)
Dim myBrush As System.Drawing.Brush = New System.Drawing.SolidBrush(myColor)
Dim g = Graphics.FromImage(MyBitMap)
g.DrawLine(myPen, OldCoord, e.Location)
g.FillEllipse(myBrush, e.X - (brSize / 2), e.Y - brSize / 2, brSize, brSize)
If OldCoord <> e.Location Then
OldCoord = e.Location
End If
g.Dispose()
Me.Image = MyBitMap
End If
End Sub
Sub Cancella()
Dim g = Graphics.FromImage(MyBitMap)
g.Clear(Me.BackColor)
g.Dispose()
Me.Image = MyBitMap
End Sub
Sub Salva(ByVal Path As String)
Me.MyBitMap.Save(Path)
End Sub
End Class