VB2005 如何将PictureBox绘制的图形打印
PictureBox1是图纸图形(图片),PictureBox2是将图片标注的尺寸计算展开的图形,是在 Private Sub PictureBox2_Paint中绘制的我用下面语句打印结果为一张白纸。请高手指点!
Private Sub 打印PToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打印PToolStripButton.Click
Dim PrintDialog = New PrintDialog
Dim PrintDocument = New PrintDocument
Dim PageSetupDialog = New PageSetupDialog
PrintDialog.PrinterSettings.Collate = True PictureBox2.HasChildren.ToString()
Dim image As Image = DirectCast(PictureBox2.Image, Image) PrintDialog.ShowDialog(PictureBox2.Image)
PrintDocument.Print()
End Sub
请高手指点。谢谢! --------------------编程问答-------------------- 补充:绘制图形语句如下:
Private Sub PictureBox2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox2.Paint
Dim R, A, B, H, F, L, n, hf, La, Lb, Lc, Ld, BB As Single
Dim g As Graphics = e.Graphics
R = CSng(TextBox1.Text) / 2
A = CSng(TextBox2.Text)
B = CSng(TextBox3.Text)
F = CSng(TextBox4.Text)
H = CSng(TextBox5.Text)
n = CSng(ComboBox1.Text)
BB = B / n
Dim Zx, Lcx, x, Lb1, Ld1 As Single
Zx = 1200 / (2 * A + 2 * B)'宽度缩放在屏幕显示范围内
hf = Sqrt(R ^ 2 - F ^ 2) + H
Lcx = (hf - Sqrt(R ^ 2 - (F + B / 2) ^ 2)) * Zx
If Lcx > 580 Then
Zx = 580 / Lcx * Zx'高度缩放在屏幕显示范围内
End If
g.Clear(Color.AntiqueWhite)
g.TranslateTransform(60, 30)
g.ScaleTransform(Zx, Zx)
hf = Sqrt(R ^ 2 - F ^ 2) + H
La = hf - Sqrt(R ^ 2 - (F - B / 2) ^ 2)
Lc = hf - Sqrt(R ^ 2 - (F + B / 2) ^ 2)
Dim mypen As Pen = New Pen(Color.Red, 1 / Zx)
g.DrawLine(mypen, 0, 0, A, 0) 'A面
g.DrawLine(mypen, 0, 0, 0, La)
g.DrawLine(mypen, 0, La, A, La)
g.DrawLine(mypen, A, 0, A, La)
g.DrawLine(mypen, A + B, 0, A + B + A, 0) 'C面
g.DrawLine(mypen, A + B, 0, A + B, Lc)
g.DrawLine(mypen, A + B, Lc, A + B + A, Lc)
g.DrawLine(mypen, A + B + A, 0, A + B + A, Lc) 'C面
Dim FFamily As FontFamily = New FontFamily("宋体")
Dim font As Font = New Font(FFamily, 16 / Zx, FontStyle.Regular, GraphicsUnit.Pixel)
Dim textA As Object = Format("A面" & "=" & Format(La, "0"))
Dim textC As Object = Format("C面" & "=" & Format(Lc, "0"))
Dim textA1 As Object = Format("A面 A=" & Format(A, "0"))
Dim textA2 As Object = Format("A=" & Format(A, "0"))
Dim textC1 As Object = Format("C面 A=" & Format(A, "0"))
Dim textC2 As Object = Format("A=" & Format(A, "0"))
Dim MySF As New StringFormat()
MySF.FormatFlags = StringFormatFlags.DirectionVertical
MySF.Alignment = StringAlignment.Far
MySF.LineAlignment = StringAlignment.Far
Dim prA As PointF = New PointF(A, La * 3 / 4)
Dim prAA As PointF = New PointF(0, La * 3 / 4)
Dim prC As PointF = New PointF(A + B + A, Lc * 3 / 4)
Dim prCC As PointF = New PointF(A + B, Lc * 3 / 4)
Dim MySF1 As New StringFormat()
MySF1.FormatFlags = StringFormatFlags.DisplayFormatControl
MySF1.Alignment = StringAlignment.Center
MySF1.LineAlignment = StringAlignment.Far
Dim prA1 As PointF = New PointF(A / 2, 0)
Dim prA2 As PointF = New PointF(A / 2, La)
Dim prC1 As PointF = New PointF(A + B + A / 2, 0)
Dim prC2 As PointF = New PointF(A + B + A / 2, Lc)
e.Graphics.DrawString(textA, font, Brushes.Red, prA, MySF)
e.Graphics.DrawString(textA, font, Brushes.Red, prAA, MySF)
e.Graphics.DrawString(textC, font, Brushes.Red, prC, MySF)
e.Graphics.DrawString(textC, font, Brushes.Red, prCC, MySF)
e.Graphics.DrawString(textA1, font, Brushes.Red, prA1, MySF1)
e.Graphics.DrawString(textA2, font, Brushes.Red, prA2, MySF1)
e.Graphics.DrawString(textC1, font, Brushes.Red, prC1, MySF1)
e.Graphics.DrawString(textC2, font, Brushes.Red, prC2, MySF1)
For L = 0 To n
Lb = hf - Sqrt(R ^ 2 - (F - B / 2 + BB * L) ^ 2)
Ld = hf - Sqrt(R ^ 2 - (F + B / 2 - BB * L) ^ 2)
x = L + 1
Lb1 = hf - Sqrt(R ^ 2 - (F - B / 2 + BB * x) ^ 2)
Ld1 = hf - Sqrt(R ^ 2 - (F + B / 2 - BB * x) ^ 2)
Dim mypen1 As Pen = New Pen(Color.Blue, 1 / Zx)
g.DrawLine(mypen1, A, 0, A + BB * L, 0) 'B面
g.DrawLine(mypen1, A + BB * L, 0, A + BB * L, Lb) 'B面
g.DrawLine(mypen1, A + B + A, 0, A + B + A + (BB * L), 0) 'D面
g.DrawLine(mypen1, A + B + A + (BB * L), 0, A + B + A + (BB * L), Ld) 'D面
Dim textB As Object = Format("B" & L & "=" & Format(Lb, "0"))
Dim textD As Object = Format("D" & L & "=" & Format(Ld, "0"))
Dim textB1 As Object = Format("B面 B=" & Format(B, "0"))
Dim textD1 As Object = Format("D面 B=" & Format(B, "0"))
Dim MySF3 As New StringFormat()
MySF3.FormatFlags = StringFormatFlags.DisplayFormatControl
MySF3.Alignment = StringAlignment.Center
MySF3.LineAlignment = StringAlignment.Far
Dim MySF4 As New StringFormat()
MySF4.FormatFlags = StringFormatFlags.DirectionVertical
MySF4.Alignment = StringAlignment.Center
MySF4.LineAlignment = StringAlignment.Near
Dim prB As PointF = New PointF(A + BB * L, Lb / 3)
Dim prD As PointF = New PointF(A + B + A + (BB * L), Ld / 3)
Dim prB1 As PointF = New PointF(A + B / 2, 0)
Dim prD1 As PointF = New PointF(A + B + A + B / 2, 0)
e.Graphics.DrawString(textB, font, Brushes.Blue, prB, MySF4)
e.Graphics.DrawString(textD, font, Brushes.Blue, prD, MySF4)
e.Graphics.DrawString(textB1, font, Brushes.Blue, prB1, MySF3)
e.Graphics.DrawString(textD1, font, Brushes.Blue, prD1, MySF3)
If x > n Then
Exit For
End If
g.DrawLine(mypen1, A + BB * L, Lb, A + BB * x, Lb1) 'B面
g.DrawLine(mypen1, A + B + A + BB * L, Ld, A + B + A + BB * x, Ld1) 'D面
Next
End Sub --------------------编程问答-------------------- 没人过问?急!
我用下列代码问题出在这句“PrintDialog.Picturebox2.PrintDialog() ”“未找到类型“PrintDialog”的公共成员“Picturebox2””请高手指点。谢谢!!!
Dim PrintDialog = New PrintDialog
Dim PrintDocument = New PrintDocument
Dim PageSetupDialog = New PageSetupDialog
PrintDialog.PrinterSettings.Collate = True
Dim Bitmap = New Bitmap(PictureBox2.ClientSize.Width, PictureBox2.ClientSize.Height)
Dim rect As Rectangle
rect = New System.Drawing.Rectangle(0, 0, PictureBox2.Width, PictureBox2.Height)
PictureBox2.DrawToBitmap(Bitmap, rect)
Bitmap.Save("my.gif", Imaging.ImageFormat.Gif)
PictureBox2.Load("my.gif")
PrintDialog.Picturebox2.PrintDialog() PrintDialog.ShowDialog()
PrintDocument.GetType()
PrintDocument.Print()
--------------------编程问答-------------------- 建议以后vb.net的问题你同时再到
http://bbs.csdn.net/forums/VBDotNET
也发一下,很多人平时只去一边 --------------------编程问答-------------------- 谢谢版主提醒。
补充:VB , 控件