如何打印vb绘制的图形?
在vb中一个窗体上画了一个sin曲线
还有一个“打印”按钮,如何实现打印
非常感谢
[解决办法]
楼上方法外提供如下演示代码:
PSet ((i - 50) * 10 + 5000, -1 * yy(i) * 100 + 4000), vbRed
Printer.Line ((i - 50) * 10 + 4995, -1 * yy(i) * 100 + 3995)-((i - 50) * 10 + 5005, -1 * yy(i) * 100 + 4005), vbRed, BF
Next
注意以上2行代码的区别,用Printer对象的属性Line来执行打印。
至于文字打印只需将xp函数的“Me.”改为“Printer.”即可。
Option Explicit
Dim i As Integer
Dim yy(100) As Single
Dim xx As Single
Dim colvb As Long
Dim x As Integer
Dim y As Integer
Dim txt As String
Dim dy As Variant
Public Function xp(colvb As Variant, x As Variant, y As Variant, txt As Variant)
Me.ForeColor = colvb 'QBColor(14)
Me.CurrentX = x
Me.CurrentY = y
Me.Print txt '
End Function
Private Sub Command1_Click()
For i = 0 To 100
xx = (i - 50) / 10
yy(i) = 0.5 * xx ^ 2 + 3 * xx - 2
Next
Line (0, 4000)-(10000, 4000)
Line (5000, 0)-(5000, 8000)
Line (6000, 3950)-(6000, 4000)
Line (4000, 3950)-(4000, 4000)
Line (5000, 3000)-(5100, 3000)
Line (5000, 5000)-(5100, 5000)
Printer.Line (5000, 5000)-(5100, 5000)
For i = 1 To 100
PSet ((i - 50) * 10 + 5000, -1 * yy(i) * 100 + 4000), vbRed
Printer.Line ((i - 50) * 10 + 4995, -1 * yy(i) * 100 + 3995)-((i - 50) * 10 + 5005, -1 * yy(i) * 100 + 4005), vbRed, BF
Next
x = 9000
y = 3900
txt = "X轴 "
colvb = vbBlue
dy = xp(colvb, x, y, txt)
x = 5100
y = 500
txt = "y轴 "
colvb = vbBlue
dy = xp(colvb, x, y, txt)
x = 5000
y = 4000
txt = "0 "
dy = xp(colvb, x, y, txt)
x = 6000 - 70
y = 4000
txt = "10 "
dy = xp(colvb, x, y, txt)
x = 4000 - 70
y = 4000
txt = "-10 "
dy = xp(colvb, x, y, txt)
x = 5100
y = 2930
txt = "10 "
dy = xp(colvb, x, y, txt)
x = 5100
y = 4930
txt = "-10 "
dy = xp(colvb, x, y, txt)
End Sub