新建From1(窗体),新建Command1(按钮CommandButton),Command2(按钮CommandBox),Picture1(PictureBox),代码:
Private Sub Form_Load() '初始化设置
Picture1.AutoSize = True
Command1.Caption = "显示网格"
Command2.Caption = "取消网格"
Form1.Caption = "显示网格图像演示程序"
End Sub
Private Sub Form_Activate() '设置网格颜色
Picture1.ForeColor = vbWhite
End Sub
Private Sub Command1_Click() '显示网格
Dim HLINESNUM As Integer
Dim WLINESNUM As Integer
Dim XX As Integer
Dim I As Integer
Dim J As Integer
Dim YY As Integer
HLINESNUM = 15 '设置网格为15*15显示
WLINESNUM = 15
Picture1.Refresh
Picture1.AutoRedraw = False
XX = Int(Picture1.ScaleWidth / WLINESNUM)
YY = Int(Picture1.ScaleHeight / HLINESNUM)
For I = 1 To HLINESNUM + 1
Picture1.Line (XX * I, 0)-(XX * I, Picture1.Height - 1)
Picture1.Line (0, YY * I)-(Picture1.Width - 1, YY * I)
Next
End Sub
Private Sub Command2_Click() '取消网格
Picture1.AutoRedraw = False
Picture1.Refresh
End Sub