【实例说明】 图像处理软件都有对网格的操作,如:显示网格,对齐网格。
【编程思路】 用Line方法。
【设计步骤】
1.新建一个标准工程,创建一个新窗体,默认名为Form1。
2.在窗体上放置一个PictureBox控件和两个CommandButton控件。
3.源程序 [素材源程序下载]
Option Explicit
Private Sub Form_Load()
Command1.Caption = "显示网格"
Command2.Caption = "取消网格"
End Sub
Private Sub Form_Activate()
Picture1.ForeColor = vbBlack
Picture1.Move 0, 0
End Sub
'显示网格
Private Sub Command1_Click()
Dim H As Long
Dim W As Long
Dim x As Integer
Dim i As Integer
Dim j As Integer
Dim y As Integer
'设置网格为15*15显示
H = 15
W = 15
Picture1.Refresh
Picture1.AutoRedraw = False
x = Int(Picture1.ScaleWidth / W)
y = Int(Picture1.ScaleHeight / H)
For i = 1 To H + 1
Picture1.Line (x * i, 0)-(x * i, Picture1.Height - 1)
Picture1.Line (0, y * i)-(Picture1.Width - 1, y * 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 Sub
|