VB语言解释
有哪位大神能从头到位详细解释下一下代码,我几乎看不懂,急、、、!!Imports System.Drawing.Drawing2D
Public Class Block
Public Const BlockSize As Integer = 25
Private colorValue As Color
Private deletionValue As Boolean = False
Private Shared rand As New Random
Public Property Color() As Color
Get
Return colorValue
End Get
Set(ByVal Value As Color)
colorValue = Value
End Set
End Property
Public Property MarkedForDeletion() As Boolean
Get
Return deletionValue
End Get
Set(ByVal Value As Boolean)
deletionValue = Value
End Set
End Property
Public Sub New(ByVal newColor As Color)
colorValue = newColor
End Sub
Public Sub New(ByVal colors() As Color)
Dim ncolors As Integer = colors.Length
Dim pickedColor As Integer
pickedColor = rand.Next(0, ncolors)
colorValue = colors(pickedColor)
End Sub
Public Sub Draw(ByVal graphics As Graphics, ByVal point As Point)
Dim brush As System.Drawing.Drawing2D.LinearGradientBrush = CreateTheBrush(point)
DrawTheCircle(graphics, brush, point)
End Sub
Private Sub DrawTheCircle(ByVal graphics As Graphics, ByVal brush As LinearGradientBrush, ByVal location As Point)
Dim topleft As Point = location
Dim bottomright As Point = New Point(location.X + BlockSize, location.Y + BlockSize)
Dim transTopLeft As Point = PointTranslator.TranslateToBL(topleft)
Dim transBottomRight As Point = PointTranslator.TranslateToBL(bottomright)
Dim transwidth As Integer = transBottomRight.X - transTopLeft.X
Dim transheight As Integer = transBottomRight.Y - transTopLeft.Y
graphics.FillEllipse(brush, New Rectangle(transTopLeft, New Size(transwidth, transheight)))
End Sub
Private Function CreateTheBrush(ByVal location As Point) As LinearGradientBrush
Dim transLocation As Point = PointTranslator.TranslateToBL(location)
Dim brushpt1 As Point = transLocation
Dim brushpt2 As New Point(transLocation.X + Block.BlockSize + 4, transLocation.Y - BlockSize - 4)
Dim brush As New LinearGradientBrush(brushpt1, brushpt2, Me.Color, System.Drawing.Color.White)
Return brush
End Function
End Class VB --------------------编程问答--------------------
Public Class Block'定义Block类了
'定义类变量
Public Const BlockSize As Integer = 25
Private colorValue As Color
Private deletionValue As Boolean = False
Private Shared rand As New Random
'定义Color属性 Get向调用者报告colorValue值,Set部分为其赋值
Public Property Color() As Color
Get
Return colorValue
End Get
Set(ByVal Value As Color)
colorValue = Value
End Set
End Property
'定义MarkedForDeletion属性
Public Property MarkedForDeletion() As Boolean
Get
Return deletionValue
End Get
Set(ByVal Value As Boolean)
deletionValue = Value
End Set
End Property
'定义New方法,该方法接受一个Color的数据
Public Sub New(ByVal newColor As Color)
colorValue = newColor
End Sub
'定义另一个New方法,该方法接受一个Color的数据类型的数组
Public Sub New(ByVal colors() As Color)
Dim ncolors As Integer = colors.Length
Dim pickedColor As Integer
pickedColor = rand.Next(0, ncolors)
colorValue = colors(pickedColor)
End Sub
'定义Draw方法,该方法调用DrawTheCircle画一个圆
Public Sub Draw(ByVal graphics As Graphics, ByVal point As Point)
Dim brush As System.Drawing.Drawing2D.LinearGradientBrush = CreateTheBrush(point)
DrawTheCircle(graphics, brush, point)
End Sub
'定义DrawTheCircle,使用指定刷brush填充
Private Sub DrawTheCircle(ByVal graphics As Graphics, ByVal brush As LinearGradientBrush, ByVal location As Point)
Dim topleft As Point = location
Dim bottomright As Point = New Point(location.X + BlockSize, location.Y + BlockSize)
Dim transTopLeft As Point = PointTranslator.TranslateToBL(topleft)
Dim transBottomRight As Point = PointTranslator.TranslateToBL(bottomright)
Dim transwidth As Integer = transBottomRight.X - transTopLeft.X
Dim transheight As Integer = transBottomRight.Y - transTopLeft.Y
graphics.FillEllipse(brush, New Rectangle(transTopLeft, New Size(transwidth, transheight)))
End Sub
'创建刷的过程
Private Function CreateTheBrush(ByVal location As Point) As LinearGradientBrush
Dim transLocation As Point = PointTranslator.TranslateToBL(location)
Dim brushpt1 As Point = transLocation
Dim brushpt2 As New Point(transLocation.X + Block.BlockSize + 4, transLocation.Y - BlockSize - 4)
Dim brush As New LinearGradientBrush(brushpt1, brushpt2, Me.Color, System.Drawing.Color.White)
Return brush
End Function
End Class
补充:VB , 基础类