自定义坐标系
Private Sub Form_activate()
Form1.Scale (-100, 100)-(100, -100)
Line (-100, 0)-(300, 0)
Line (0, 100)-(0, -150)
DrawWidth = 10
Form1.Circle (0, 0), 0, vbRed
CurrentX = 0: CurrentY = 0: Print "(0,0)"
CurrentX = 90: CurrentY = 10: Print "X轴"
CurrentX = 5: CurrentY = 95: Print "Y轴"
End Sub
首先需要明确Scale方法:用以定义 Form、PictureBox 或 Printer 的坐标系统。不支持命名参数。
Scale要么不带参数,要么带两个参数,即(x1,y1)和(x2,y2),这两个参数之间必须使用“-”连接。
(x1,y1)表示Form的左上角坐标,(x2,y2)表示Form的右下角坐标。
Scale方法使用之后意味着Form的布局范围在以(x1,y1)和(x2,y2)作为对角点的矩形之内。
您的例程中,Form的坐标范围就在(-100,100)和(100,-100)决定的矩形之内。
Line方法画线的时候,第一句表示从(0,100)画到(0,-100),就意味着画了一条竖线。这条竖线正式在窗体中间。(此时Form的四个顶点的分别为 左上(-100,100) 左下(-100,-100) 右上(100,100) 右下(100,-100))
第二句同理可得。
绘图1
Private Sub Form_Resize()
Form1.ForeColor = QBColor(12)
Line (500, 500)-Step(500, 0)
Line -Step(0, 500)
Line -Step(-500, 0)
Line -Step(0, -500)
Line (1000, 1000)-Step(500, 500), , B
Line (1500, 500)-(2000, 1000), , BF
End Sub
绘圆形
Private Sub Form_Resize()
Dim xpos, ypos As Integer
Dim lim, rad As Integer
Dim r, g, b As Integer
ScaleMode = 3
xpos = Me.ScaleWidth / 2
ypos = Me.ScaleHeight / 2
If xpos > ypos Then
lim = ypos
Else
lim = xpos
End If
For rad = 0 To lim
Randomize
r = 255 * Rnd: g = 255 * Rnd: b = 255 * Rnd
Circle (xpos, ypos), rad, RGB(r, g, b)
Next rad
End Sub
循环设置控件数组
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 5
Shape1(i).Shape = i
Shape1(i).FillStyle = i
Next
End Sub
绘制网格
Private Sub Command1_Click()
Dim xpos, ypos As Integer
Dim rad As Integer
Form1.Refresh
Form1.AutoRedraw = False
Form1.ForeColor = &H80000003
xpos = Int(Form1.ScaleWidth) / Val(Combo1.Text)
ypos = Int(Form1.ScaleHeight) / Val(Combo2.Text)
For rad = 1 To Val(Combo1.Text) + 1
Line (0, i * ypos)-(Form1.Width, i * ypos)
Next
For rad = 1 To Val(Combo2.Text) + 1
Line (i * xpos, 0)-(i * xpos, Form1.Height)
Next
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 200
Combo1.AddItem (i)
Combo2.AddItem (i)
Next
End Sub
绘制网格2
Private Sub Command1_Click()
Dim x, y, i As Integer
Form1.Refresh
Form1.AutoRedraw = False
Form1.ForeColor = &H80000003
If IsNumeric(Combo1.Text) = 0 Or IsNumeric(Combo2.Text) = 0 Then
MsgBox "请输入数据!", vbInformation, "信息提示"
Else
x = Int(Form1.ScaleWidth / Val(Combo1.Text))
y = Int(Form1.ScaleHeight / Val(Combo2.Text))
For i = 1 To Val(Combo2.Text) + 1
Form1.Line (0, y * i)-(Form1.ScaleWidth, y * i)
Next
For i = 1 To Val(Combo1.Text) + 1
Form1.Line (x * i, 0)-(x * i, Form1.ScaleHeight)
Next
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 1000
Combo1.AddItem (i)
Combo2.AddItem (i)
Next
End Sub
Private Sub combo1_LostFocus()
If Combo1.Text = "" Then
Combo1.Text = 30
End If
End Sub
Private Sub combo2_LostFocus()
If Combo2.Text = "" Then
Combo2.Text = 40
End If
End Sub
进度条
Private Sub Command1_Click()
Dim i As Integer
Dim t As Long
Dim per As String
Dim cx, cy As Single
For i = 0 To Picture1.ScaleWidth
Picture1.DrawMode = vbCopyPen
Picture1.Line (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight), QBColor(7), BF
per = Format(i / Picture1.ScaleWidth, "0.00%")
cx = (Picture1.ScaleWidth - Picture1.TextWidth(per)) / 2
cy = (Picture1.ScaleHeight - Picture1.TextHeight(per)) / 2
Picture1.CurrentX = cx
Picture1.CurrentY = cy
Picture1.Print per
Picture1.DrawMode = vbXorPen
Picture1.Line (0, 0)-(i, Picture1.ScaleHeight), vbRed, BF
For t = 0 To 5000
DoEvents
Next t
Next i
MsgBox "完成"
End Sub
Private Sub Form_Load()
Picture1.FontSize = 14
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
进度条修改
Private Sub Command1_Click()
Dim i As Integer
Dim per As String
Dim x, y As Single
Dim t As Long
w = Picture1.ScaleWidth
h = Picture1.ScaleHeight
For i = 0 To w
Picture1.DrawMode = vbCopyPen
Picture1.Line (0, 0)-(w, h), vbGreen, BF
per = Format(i / w, "0.00%")
x = (w - Picture1.TextWidth(per)) / 2
y = (h - Picture1.TextHeight(per)) / 2
Picture1.CurrentX = x
Picture1.CurrentY = y
Picture1.Print per
Picture1.DrawMode = vbXorPen
Picture1.Line (0, 0)-(i, h), vbRed, BF
For t = 1 To 5000
DoEvents
Next t
Next i
End Sub
Private Sub Form_Load()
Picture1.FontSize = 20
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub