使用缓冲方式绘图:
初始化
Picture1.Visible = False
Picture1.AutoRedraw = True
Picture1.Appearance = 0
程序代码:
Public Sub view()
'显示每个格子
If hd < Screen.TwipsPerPixelX * 3 Or ld < Screen.TwipsPerPixelY * 3 Then Exit Sub
'如果不够绘图,则直接退出
Dim i As Long, j As Long
For i = 0 To 横 - 1
For j = 0 To 竖 - 1
If z(i + 1, j + 1) = 1 Then '生,就用生画格
Picture1.Line (i * hd + Screen.TwipsPerPixelX, j * ld + Screen.TwipsPerPixelY)-(i * hd + hd - Screen.TwipsPerPixelX, j * ld + ld - Screen.TwipsPerPixelY), 生, BF
Else '死,就用死画格
Picture1.Line (i * hd + Screen.TwipsPerPixelX, j * ld + Screen.TwipsPerPixelY)-(i * hd + hd - Screen.TwipsPerPixelX, j * ld + ld - Screen.TwipsPerPixelY), 死, BF
End If
Next j
Next i
Call Form_Paint
End Sub
Private Sub Form_Paint()
'
Me.PaintPicture Picture1.Image, 0, 0
End Sub
Private Sub Form_Resize()
'窗体大小改变时,计算格子大小
Dim i As Long, j As Long
Picture1.Height = Me.ScaleHeight
Picture1.Width = Me.ScaleWidth
i = Picture1.ScaleWidth
hd = i \ 横
i = Picture1.ScaleHeight
ld = i \ 竖
'绘制网络
Picture1.Cls '清屏
For i = 0 To 横 - 1
For j = 0 To 竖 - 1
Picture1.Line (i * hd, j * ld)-(i * hd + hd, j * ld + ld), 灰, B '副格子线,按每个格子均画线,也可以按横和竖分别画线
Next j
Next i
Call view '重绘格子
Call Form_Paint '缩小时,不会产生重绘事件,需要手动调用
End Sub