Dim firstflag
Dim R, PI
Dim prehr, premin, prex, preySub drawcircle()
Dim i, x1, y1
Circle (0, 0), R
For i = 0 To 60
x1 = (R - 50) * Sin(i * 2 * PI / 60)
y1 = (R - 50) * Cos(i * PI / 30)
FillStyle = 0
If i Mod 5 = 0 Then
FillColor = QBColor(0)
Circle (x1, y1), 40
Else
FillColor = QBColor(7)
Circle (x1, y1), 20
End If
Next
End SubPrivate Sub Form_Load()
Dim cx, cy
cx = ScaleWidth / 2
cy = ScaleHeight / 2Scale (-cx, cy)-(cx, -cy)
firstflag = True
Label1.Font.Bold = -1
Label1.Font.Size = 16
End SubPrivate Sub Timer1_Timer()
Dim x, y
Dim ttime, black, red, green
Dim hr, min, sec, h
R = 1000
PI = 3.14159
If firstflag = True Then
drawcircle
End If
ttime = Now
hr = Hour(ttime)
ht = hr Mod 12
min = Minute(ttime)
sec = Second(ttime)
DrawWidth = 3
black = RGB(0, 0, 0)
green = RGB(0, 255, 0)
red = RGB(255, 0, 0)
If firstflag = True Then
DrawMode = 10
h = hr * 5 + min / 12
x = 500 * Sin(h * PI / 30)
y = 500 * Cos(h * PI / 30)
prehr = hr
Line (0, 0)-(x, y), black
x = 650 * Sin(min * PI / 30)
y = 650 * Cos(min * PI / 30)
Line (0, 0)-(x, y), green
premin = min
End If
DrawMode = 10
If premin <> min Then
h = prehr * 5 + premin / 12
x = 500 * Sin(h * PI / 30)
y = 500 * Cos(h * PI / 30)
Line (0, 0)-(x, y), black '清除原时针
x = 650 * Sin(premin * PI / 30)
y = 650 * Cos(premin * PI / 30)
Line (0, 0)-(x, y), green '清除原分针
h = hr * 5 + min / 12
x = 500 * Sin(h * PI / 30)
y = 500 * Cos(h * PI / 30)
Line (0, 0)-(x, y), black '绘制时针
prehr = hr
x = 650 * Sin(min * PI / 30)
y = 650 * Cos(min * PI / 30)
Line (0, 0)-(x, y), green '绘制分针
premin = min
End If
x = 800 * Sin(sec * PI / 30)
y = 800 * Cos(sec * PI / 30)
DrawWidth = 1
If firstflag <> True Then
Line (0, 0)-(prex, prey), red
End If
Line (0, 0)-(x, y), red
prex = x
prey = y
firstflag = False
Label1.Caption = Now
End Sub
这段代码实现了一个钟表的绘制,我想知道通过DrawMode=10是怎样实现时针分针的清除和绘制的,麻烦详细的解释一下这里进行了怎样的颜色按位操作,谢谢!
Dim R, PI
Dim prehr, premin, prex, preySub drawcircle()
Dim i, x1, y1
Circle (0, 0), R
For i = 0 To 60
x1 = (R - 50) * Sin(i * 2 * PI / 60)
y1 = (R - 50) * Cos(i * PI / 30)
FillStyle = 0
If i Mod 5 = 0 Then
FillColor = QBColor(0)
Circle (x1, y1), 40
Else
FillColor = QBColor(7)
Circle (x1, y1), 20
End If
Next
End SubPrivate Sub Form_Load()
Dim cx, cy
cx = ScaleWidth / 2
cy = ScaleHeight / 2Scale (-cx, cy)-(cx, -cy)
firstflag = True
Label1.Font.Bold = -1
Label1.Font.Size = 16
End SubPrivate Sub Timer1_Timer()
Dim x, y
Dim ttime, black, red, green
Dim hr, min, sec, h
R = 1000
PI = 3.14159
If firstflag = True Then
drawcircle
End If
ttime = Now
hr = Hour(ttime)
ht = hr Mod 12
min = Minute(ttime)
sec = Second(ttime)
DrawWidth = 3
black = RGB(0, 0, 0)
green = RGB(0, 255, 0)
red = RGB(255, 0, 0)
If firstflag = True Then
DrawMode = 10
h = hr * 5 + min / 12
x = 500 * Sin(h * PI / 30)
y = 500 * Cos(h * PI / 30)
prehr = hr
Line (0, 0)-(x, y), black
x = 650 * Sin(min * PI / 30)
y = 650 * Cos(min * PI / 30)
Line (0, 0)-(x, y), green
premin = min
End If
DrawMode = 10
If premin <> min Then
h = prehr * 5 + premin / 12
x = 500 * Sin(h * PI / 30)
y = 500 * Cos(h * PI / 30)
Line (0, 0)-(x, y), black '清除原时针
x = 650 * Sin(premin * PI / 30)
y = 650 * Cos(premin * PI / 30)
Line (0, 0)-(x, y), green '清除原分针
h = hr * 5 + min / 12
x = 500 * Sin(h * PI / 30)
y = 500 * Cos(h * PI / 30)
Line (0, 0)-(x, y), black '绘制时针
prehr = hr
x = 650 * Sin(min * PI / 30)
y = 650 * Cos(min * PI / 30)
Line (0, 0)-(x, y), green '绘制分针
premin = min
End If
x = 800 * Sin(sec * PI / 30)
y = 800 * Cos(sec * PI / 30)
DrawWidth = 1
If firstflag <> True Then
Line (0, 0)-(prex, prey), red
End If
Line (0, 0)-(x, y), red
prex = x
prey = y
firstflag = False
Label1.Caption = Now
End Sub
这段代码实现了一个钟表的绘制,我想知道通过DrawMode=10是怎样实现时针分针的清除和绘制的,麻烦详细的解释一下这里进行了怎样的颜色按位操作,谢谢!
常数 设置值 描述
VbBlackness 1 黑色。
VbNotMergePen 2 非或笔 - 与设置值 15 相反 (Merge Pen)。
VbMaskNotPen 3 与非笔 - 背景色以及画笔反相二者共有颜色的组合。
VbNotCopyPen 4 非复制笔 - 设置值 13 (Copy Pen) 的反相
VbMaskPenNot 5 与笔非 - 画笔以及显示反相二者共有颜色的组合。
VbInvert 6 反转 - 显示颜色的反相
VbXorPen 7 异或笔 - 画笔的颜色以及显示颜色的组合,只取其一。
VbNotMaskPen 8 非与笔 - 设置值 9 (Mask Pen) 的反相。
VbMaskPen 9 与笔 - 画笔和显示二者共有颜色的组合。
VbNotXorPen 10 非异或笔 - 方式 7 的反相 (Xor Pen)。
VbNop 11 无操作 - 输出保持不变。该设置实际上关闭画图。
VbMergeNotPen 12 或非笔 - 显示颜色与画笔颜色反相的组合。
VbCopyPen 13 复制笔(缺省值) - 由 ForeColor 属性指定的颜色。
VbMergePenNot 14 或笔非 - 画笔颜色与显示颜色的反相的组合。
VbMergePen 15 或笔 - 画笔颜色与显示颜色的组合。
VbWhiteness 16 白色。
Private Sub Command1_Click()
Static b As Boolean
b = Not b
Dim c As Long
c = RGB(255, 0, 0)
' c = RGB(0, 255, 255)
If b = True Then
Me.Line (20, 20)-(1500, 1000), c, BF
Else
Me.Line (20, 20)-(1500, 1000), c, BF
End If
End SubPrivate Sub Form_Load()
Me.DrawMode = 7 '或改为10
Me.AutoRedraw = True
End Sub