Dim strx0 As Double '起始打印位 Dim stry0 As Double Dim enx As Double '表格最大长宽 Dim eny As Double Dim xzh As Double '总行数 Dim yju As Double '行距 Dim xpju As Integer '文字偏移量 Dim ypju As Integer
Dim i As Integer Dim j As Integer Dim ynow As Double 'Y坐标 Dim xnow As Double 'X坐标 Printer.Orientation = 1 Printer.Font.Name = "仿宋_GB2312" ' !!!! Printer.Font.Name = "Arial" Printer.Font.Name = "仿宋_GB2312" Printer.Font.Bold = False Printer.Font.Italic = False Printer.Font.Underline = False Printer.Font.Strikethrough = False Printer.ForeColor = &HFF&
我不知道怎么控制打印出图像的位置。和打印文字的位置字体等。要求这些可设置就OK了。最好加个文件打开框,小弟实在是个VB菜鸟。请各位大虾帮助。
有所谓,天生我材必有用,千分散尽还复来。
小弟邮箱MSN是:[email protected]新贴送分,决不食言
我不知道怎么精确定位每个图片的位置.还有文字的位置,字体,字号等.
最好能使用WINDOWS的标准字体属性框来选择字体字号.要求就这些.我昨天看了一下,好象用printer就能搞定,可我不晓得怎么用啊,手头找不到vb6的MSDN.
Dim Answer As String, HorizontalMargin, VerticalMargin As Single
Dim MyCenteredText As String, MyCenteredTextWidth As Single
Dim MyLeftText As String, MyLeftTextWidth As Single
Dim MyRightText As String, MyRightTextWidth As Single
Dim txtGrid11, txtGrid12, txtGrid13, txtGrid14, txtGrid21, txtGrid22 As String
Dim txtGrid23, txtGrid24, txtGrid31, txtGrid32, txtGrid33, txtGrid34 As String
Dim MyGridTitle As String, MyGridTitleWidth As Single
Dim Row1Col1Left, Row1Col2Left, Row1Col3Left, Row1Col4Left As Single
Dim Row2Col1Left, Row2Col2Left, Row2Col3Left, Row2Col4Left As Single
Dim Row3Col1Left, Row3Col2Left, Row3Col3Left, Row3Col4Left As Single
Dim Row1Top, Row2Top, Row3Top, ImageLeft, ImageTop As Single
Answer = MsgBox("confirm printing on " & Printer.DeviceName, vbYesNo)
If Answer = vbNo Then Exit Sub
Printer.ScaleMode = vbCentimeters
HorizontalMargin = (21 - Printer.ScaleWidth) / 2
VerticalMargin = (29.7 - Printer.ScaleHeight) / 2
HorizontalMargin = 1 + HorizontalMargin
VerticalMargin = 1.5 + VerticalMargin
Printer.Print "";
Printer.Line (HorizontalMargin, VerticalMargin)-(21 - HorizontalMargin, 29.7 - VerticalMargin), RGB(255, 0, 0), B
Printer.FontName = "Arial"
Printer.FontSize = 12
Printer.FontBold = True 'we want bold
Printer.FontItalic = False 'no italic
Printer.FontUnderline = False 'no underline
Printer.FontStrikethru = False 'no strike
Printer.ForeColor = RGB(0, 0, 0) 'color black
MyCenteredText = "This is centered text in Arial 12 Bold"
MyCenteredTextWidth = Printer.TextWidth(MyCenteredText)
Printer.CurrentX = (21 - MyCenteredTextWidth) / 2
Printer.CurrentY = VerticalMargin + 0.5
Printer.Print MyCenteredText
Printer.FontName = "Courier New"
Printer.FontSize = 10
Printer.FontBold = False 'no bold
Printer.FontItalic = True 'we use italic
Printer.FontUnderline = False 'no underline
Printer.FontStrikethru = False 'no strike
Printer.ForeColor = RGB(0, 0, 0) 'color blackMyLeftText = "Courier New on the Left"
MyLeftTextWidth = Printer.TextWidth(MyLeftText)
If MyLeftTextWidth > 21 - (HorizontalMargin * 2) Then Exit SubPrinter.CurrentX = HorizontalMargin
Printer.CurrentY = VerticalMargin + 2
Printer.Print MyLeftText;MyRightText = "Courier New on the Right"
MyRightTextWidth = Printer.TextWidth(MyRightText)
If MyRightTextWidth > 21 - (HorizontalMargin) Then Exit Sub
Printer.CurrentX = 21 - (HorizontalMargin) - MyRightTextWidth
Printer.Print MyRightTexttxtGrid11 = "row1 & col1"
txtGrid12 = "row1 & col2"
txtGrid13 = "row1 & col3"
txtGrid14 = "row1 & col4"
txtGrid21 = "row2 & col1"
txtGrid22 = "row2 & col2"
txtGrid23 = "row2 & col3"
txtGrid24 = "row2 & col4"
txtGrid31 = "row3 & col1"
txtGrid32 = "row3 & col2"
txtGrid33 = "row3 & col3"
txtGrid34 = "row3 & col4"
Printer.ForeColor = RGB(0, 255, 0)Printer.Line (1 + HorizontalMargin, 4 + VerticalMargin)-(16 + HorizontalMargin, 4 + VerticalMargin)
Printer.Line (1 + HorizontalMargin, 7 + VerticalMargin)-(16 + HorizontalMargin, 7 + VerticalMargin)
Printer.Line (1 + HorizontalMargin, 4 + VerticalMargin)-(1 + HorizontalMargin, 7 + VerticalMargin)
Printer.Line (16 + HorizontalMargin, 4 + VerticalMargin)-(16 + HorizontalMargin, 7 + VerticalMargin)
Printer.Line (1 + HorizontalMargin, 5 + VerticalMargin)-(16 + HorizontalMargin, 5 + VerticalMargin)
Printer.Line (1 + HorizontalMargin, 6 + VerticalMargin)-(16 + HorizontalMargin, 6 + VerticalMargin)
Printer.Line (3 + HorizontalMargin, 4 + VerticalMargin)-(3 + HorizontalMargin, 7 + VerticalMargin)
Printer.Line (9 + HorizontalMargin, 4 + VerticalMargin)-(9 + HorizontalMargin, 7 + VerticalMargin)
Printer.Line (14 + HorizontalMargin, 4 + VerticalMargin)-(14 + HorizontalMargin, 7 + VerticalMargin)Printer.ForeColor = RGB(0, 0, 0)Printer.FontName = "Arial"
Printer.FontSize = 10
Printer.FontBold = False 'no bold
Printer.FontItalic = False 'no italic
Printer.FontUnderline = False 'no underline
Printer.FontStrikethru = False 'no strike
MyGridTitle = "And this is a little table"
MyGridTitleWidth = Printer.TextWidth(MyGridTitle)
Printer.CurrentX = HorizontalMargin + 1 + ((15 - MyGridTitleWidth) / 2)
Printer.CurrentY = 4 + VerticalMargin - (Printer.TextHeight(MyGridTitle) + 0.1)
Printer.Print MyGridTitle
Row1Col1Left = 1 + HorizontalMargin + 0.1
Row1Col2Left = 3 + HorizontalMargin + 0.1
Row1Col3Left = 9 + HorizontalMargin + 0.1
Row1Col4Left = 14 + HorizontalMargin + 0.1Row1Top = 4 + VerticalMargin + ((1 - Printer.TextHeight(txtGrid11)) / 2)
'
Row2Top = 5 + VerticalMargin + ((1 - Printer.TextHeight(txtGrid11)) / 2)
Row3Top = 6 + VerticalMargin + ((1 - Printer.TextHeight(txtGrid11)) / 2)
'
Row2Col1Left = 1 + HorizontalMargin + 0.1 '(column 1)
Row2Col2Left = 3 + HorizontalMargin + 0.1 '(column 2)
Row2Col3Left = 9 + HorizontalMargin + 0.1 '(column 3)
Row2Col4Left = 14 + HorizontalMargin + 0.1 '(column 4)
'
Row3Col1Left = 1 + HorizontalMargin + 0.1 '(column 1)
Row3Col2Left = 3 + HorizontalMargin + 0.1 '(column 2)
Row3Col3Left = 9 + HorizontalMargin + 0.1 '(column 3)
Row3Col4Left = 14 + HorizontalMargin + 0.1 '(column 4)
'
Printer.CurrentY = Row1Top
Printer.CurrentX = Row1Col1Left
Printer.Print txtGrid11;
Printer.CurrentX = Row1Col2Left
Printer.Print txtGrid12;
Printer.CurrentX = Row1Col3Left
Printer.Print txtGrid13;
Printer.CurrentX = Row1Col4Left
Printer.Print txtGrid14
'
Printer.CurrentY = Row2Top
Printer.CurrentX = Row2Col1Left
Printer.Print txtGrid21;
Printer.CurrentX = Row2Col2Left
Printer.Print txtGrid22;
Printer.CurrentX = Row2Col3Left
Printer.Print txtGrid23;
Printer.CurrentX = Row2Col4Left
Printer.Print txtGrid24
'
Printer.CurrentY = Row3Top
Printer.CurrentX = Row3Col1Left
Printer.Print txtGrid31;
Printer.CurrentX = Row3Col2Left
Printer.Print txtGrid32;
Printer.CurrentX = Row3Col3Left
Printer.Print txtGrid33;
Printer.CurrentX = Row3Col4Left
Printer.Print txtGrid34Picture2.ScaleMode = vbCentimeters
Picture2.Picture = LoadPicture(App.Path & "\dark_shadow.jpg")
Picture2.AutoSize = True
Picture2.Refresh
Picture2.AutoSize = FalseImageLeft = (21 - Picture2.ScaleWidth) / 2ImageTop = 12Printer.ScaleMode = vbCentimeters
Printer.PaintPicture Picture2.Picture, ImageLeft, ImageTopPrinter.EndDoc
End SubPrivate Sub Command2_Click()
End
End Sub
Dim stry0 As Double
Dim enx As Double '表格最大长宽
Dim eny As Double
Dim xzh As Double '总行数
Dim yju As Double '行距
Dim xpju As Integer '文字偏移量
Dim ypju As Integer
Dim i As Integer
Dim j As Integer
Dim ynow As Double 'Y坐标
Dim xnow As Double 'X坐标 Printer.Orientation = 1
Printer.Font.Name = "仿宋_GB2312" ' !!!!
Printer.Font.Name = "Arial"
Printer.Font.Name = "仿宋_GB2312"
Printer.Font.Bold = False
Printer.Font.Italic = False
Printer.Font.Underline = False
Printer.Font.Strikethrough = False
Printer.ForeColor = &HFF&
yju = 400
xzh = 38 '微调
xpju = 20
ypju = 80 '100
strx0 = 500
stry0 = 100
enx = 11000 '最大宽度
eny = stry0 + xzh * yju
xnow = strx0
ynow = stry0
Printer.Font.Name = "楷体_GB2312"
Printer.Font.Bold = True
Printer.Font.Size = 20
Printer.CurrentX = xnow + 3000(数字自定义)
Printer.CurrentY = ynow
Printer.Print "aaaaaaaaaa" Printer.EndDoc
Printer.Orientation = 1
基本就是这样定位的。
如果还有不明白的你再说