用VB编程绘制网格图像
首先:做准备工作:在FORM1上新建一个PICTURE1(并装载一幅你喜爱的图像)和两个COMMAND命令按钮在PICTURE1下面(即COMMAND1和COMMAND2),其他属性不变,然后输入以下代码:
Private Sub Form_Load()//初始化设置
Picture1.AutoSize = True
Command1.Caption = ″显示网格″
Command2.Caption = ″取消网格″
Form1.Caption = ″显示网格图像演示程序″
End Sub
----------------
Private Sub Form_Activate()//设置网格颜色
Picture1.ForeColor = vbWhite
Picture1.Move 0,0
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
------------
Private Sub Form_Unload(Cancel As Integer)
Unload Me //结束程序
End
End Sub
好了,请按F5运行一下吧,效果如何?
注:以上程序在中文WINDOWS98,中文VB5.0专业版中调试通过!