求助:关于picture1.CurrentX的问题

egxsun 2003-09-30 08:49:40
我用数组事先设好值,比如
str(0) = "00"
str(1) = "11"
str(2) = "22hftyr"
str(3) = "333"
str(4) = "4444"
str(5) = "55555"
str(6) = "666666"
str(7) = "7777777urtuyrtur"
str(8) = "88888888"
str(9) = "999999999"
然后用
For j = 0 To 9
ii = Picture1.TextWidth(str(j))
Picture1.CurrentX = (Picture1.ScaleWidth - ii) / 2
Picture1.CurrentY = Picture1.CurrentY + 1
Picture1.Print str(j)
Next
可以控制字符在中间打印出来,但是我用text1文本框(可以多行)输入,然后用
str = Split(Text1.Text, Chr(13))取到str()数组里,再用像上面的循环打印
可是只有第一行是在中间打印出来,其他行都在最左边开始打印,不知道为什么?请哪位帮帮我!
...全文
293 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Fearfulness 2003-09-30
  • 打赏
  • 举报
回复
textbox里面得换行是Chr(10) & Chr(13) 因此你应该将str = Split(Text1.Text, Chr(13))改为str = Split(Text1.Text, Chr(13) & chr(10))
射天狼 2003-09-30
  • 打赏
  • 举报
回复
Option Explicit

Private Sub Command1_Click()
Dim Str() As String, j As Long, ii As Long

Str = Split(Text1.Text, vbCrLf)
For j = 0 To UBound(Str)
ii = Picture1.TextWidth(Str(j))
Picture1.CurrentX = (Picture1.ScaleWidth - ii) / 2
Picture1.CurrentY = Picture1.CurrentY + 1
Picture1.Print Str(j)
Next

End Sub

我用的就是你说的方法,可以打印到中间啊~~
LichKingSZ 2003-09-30
  • 打赏
  • 举报
回复
str = Split(Text1.Text, vbcrlf)
射天狼 2003-09-30
  • 打赏
  • 举报
回复
首先用print方法无法实现打印回车,另外,每打一个字条款都要设定打印的位置.
汽车动力性计算 VB源代码 部分代码 Private Sub Command2_Click() '加速度曲线 Label17.Caption = "" Picture1.Cls Picture1.Scale (-12, 3)-(125, -0.3) Picture1.Line (0, 0)-(0, 2.8) Picture1.Line (0, 0)-(120, 0) For j = 1 To 100 For i = 1 To 10 Picture1.Line (0, i * 0.25)-(2, i * 0.25) '取纵坐标刻度线 Picture1.Line (i * 10, 0.04)-(i * 10, 0) '取横坐标刻度线 Picture1.Line (1.5 - j * 0.015, 2.65)-(0, 2.8) '画纵坐标箭头 Picture1.Line (-1.5 + j * 0.015, 2.65)-(0, 2.8) Picture1.Line (120, 0)-(114, 0.05 - j * 0.0005) '画横坐标箭头 Picture1.Line (120, 0)-(114, -0.05 + j * 0.0005) Picture1.CurrentX = -4: Picture1.CurrentY = -0.02: Picture1.Print 0 Picture1.CurrentX = -10: Picture1.CurrentY = i * 0.25 + 0.02: Picture1.Print i * 0.25 '读取纵坐标刻度线数值 Picture1.CurrentX = 16: Picture1.CurrentY = 2.7: Picture1.Print "a / (m/s)" Picture1.CurrentX = 10 * i - 7: Picture1.CurrentY = -0.05: Picture1.Print i * 10 '读取纵坐标刻度线数值 Picture1.CurrentX = 103: Picture1.CurrentY = -0.05: Picture1.Print "Ua/(Km / h)" Next i Next j For i = 1 To 5 Ff = 0: ft = 0: a = 0: Ua = 0 If i = 1 Then Ig = 5.56: Uamax = 0.377 * r * Nmax / (Ig * io): Uamin = 0.377 * r * Nmin / (Ig * io) If i = 2 Then Ig = 2.769: Uamax = 0.377 * r * Nmax / (Ig * io): Uamin = 0.377 * r * Nmin / (Ig * io) If i = 3 Then Ig = 1.644: Uamax = 0.377 * r * Nmax / (Ig * io): Uamin = 0.377 * r * Nmin / (Ig * io) If i = 4 Then Ig = 1: Uamax = 0.377 * r * Nmax / (Ig * io): Uamin = 0.377 * r * Nmin / (Ig * io) If i = 5 Then Ig = 0.793: Uamax = 0.377 * r * Nmax / (Ig * io): Uamin = 0.377 * r * Nmin / (Ig * io) Ff = M3 * 9.8 * f + CDA * Ua * Ua / 21.15 For Ua = Uamin To Uamax Step 0.01 n = Ua * io * Ig / (0.377 * r) tq = -19.313 + 295.27 * (n / 1000) - 165.44 * (n / 1000) ^ 2 + 40.874 * (n / 1000) ^ 3 - 3.8445 * (n / 1000) ^ 4 ft = tq * Ig * io * Nt / r δ = 1 + (Iw1 + Iw2 + Iff) / (M3 * r ^ 2) + Iff * Ig ^ 2 * io ^ 2 * Nt / (M3 * r ^ 2) a = (ft - Ff) / (M3 * δ) If a > 0 Then Picture1.PSet (Ua, a), RGB(100 + i ^ 2 * 6 - 15 * i, i ^ 2 * 15 - i * 5, i ^ 4 / 4 + 10) Next Ua Next i
Private Sub Image5_Click() '打印报表 Dim i As Integer Dim pageleft As Integer Dim pageheader As Integer Dim pagefooter As Integer Dim pageright As Integer Dim startx As Integer Dim starty As Integer Dim startline As Integer Dim endline As Integer Dim usewidth As Integer Dim useheight As Integer pageheader = 25 pagefooter = 25 pageleft = 20 pageright = 20 '定义纸张类型A4 Printer.FontSize = 20 Printer.PaperSize = 9 Printer.ScaleMode = 6 Printer.FontBold = False Printer.ScaleLeft = -20 Printer.ScaleTop = -25 Printer.ScaleWidth = 210 Printer.ScaleHeight = 297 usewidth = Printer.ScaleWidth - 40 useheight = Printer.ScaleHeight - 50 Printer.CurrentX = 0 Printer.CurrentY = 0 Printer.DrawWidth = 2 '打印主标题 Printer.FontSize = 20 Printer.CurrentX = (usewidth - Printer.TextWidth(Me.Text1.Text & "经济情况表")) / 2 Printer.CurrentY = Printer.ScaleTop Printer.Print Me.Text1.Text & "经济情况表" '打印空白行 Printer.FontSize = 8 Printer.CurrentX = (usewidth - Printer.TextWidth("")) / 2 Printer.CurrentY = Printer.CurrentY + 1 Printer.Print "" '打印副标题 Printer.FontSize = 15 Printer.CurrentX = (usewidth - Printer.TextWidth(commonth & "月份经济情况报表")) / 2 Printer.CurrentY = Printer.CurrentY + 1 Printer.Print commonth & "月份经济情况报表" '打印空白行 Printer.FontSize = 8 Printer.CurrentX = (usewidth - Printer.TextWidth("")) / 2 Printer.CurrentY = Printer.CurrentY + 1 Printer.Print "" '打印表的内容 '首先打印第一条横线 '打印最上边的第一条横线 Printer.CurrentX = pageleft + Printer.ScaleLeft startline = Printer.CurrentY + 1 Printer.Line -((Printer.ScaleLeft + Printer.ScaleWidth - pageleft), Printer.CurrentY) Printer.FontSize = 12 Printer.CurrentY = Printer.CurrentY + 1 starty = Printer.CurrentY Printer.CurrentX = ((Printer.ScaleWidth - 40) / 3 - Printer.TextWidth("")) / 2 Printer.Print "" Printer.FontSize = 12 Printer.CurrentX = usewidth / 3 + ((usewidth / 3 - Printer.TextWidth("今年经济情况")) / 2) Printer.CurrentY = starty Printer.Print "今年经济情况(万元)" Printer.FontSize = 12 Printer.CurrentX = (usewidth / 3) * 2 + ((usewidth / 3 - Printer.TextWidth("去年经济情况")) / 2) Printer.CurrentY = starty Printer.Print "去年经济情况(万元)" Printer.CurrentX = pageleft + Printer.ScaleLeft Printer.CurrentY = Printer.CurrentY + 1 Printer.Line -((Printer.ScaleLeft + Printer.ScaleWidth - pageleft), Printer.CurrentY) Printer.CurrentY = Printer.CurrentY + 1 For i = 0 To 10 '判断是否该页已打满 Me.MSFlexGrid1.Row = i If Printer.CurrentY >= useheight Then '打印横线 Printer.CurrentX = Printer.ScaleLeft + pageleft Printer.Line -((Printer.ScaleLeft + Printer.ScaleWidth - pageleft), Printer.CurrentY) Printer.CurrentY = Printer.CurrentY + 1 '打印四条竖线 endline = Printer.CurrentY Printer.Line (0, startline)-(0, endline) Printer.Line (usewidth / 3, startline)-(usewidth / 3, endline) Printer.Line ((usewidth / 3) * 2, startline)-((usewidth / 3) * 2, endline) Printer.Line (usewidth, startline)-(usewidth, endline) '打印页号 Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(Printer.Page)) / 3 - pageleft Printer.CurrentY = useheight + 3 Printer.Print Printer.Page Printer.NewPage 'NewPage告诉打印机,程序对当前输出页的发送已经结束。Printer对象应开始新的一页。 Printer.CurrentX = pageleft + Printer.ScaleLeft Printer.CurrentY = pageheader + Printer.ScaleTop startline = Printer.CurrentY Else '打印一行数据 Me.MSFlexGrid1.Col = 0 Printer.CurrentX = ((Printer.ScaleWidth - 40) / 3 - Printer.TextWidth(Me.MSFlexGrid1.Text)) / 8 starty = Printer.CurrentY Printer.Print Me.MSFlexGrid1.Text Me.MSFlexGrid1.Col = 1 Printer.CurrentX = (Printer.ScaleWidth - 40) / 3 + ((Printer.ScaleWidth - 40) / 3 - Printer.TextWidth(Me.MSFlexGrid1.Text)) / 2 Printer.CurrentY = starty Printer.Print Me.MSFlexGrid1.Text Me.MSFlexGrid1.Col = 2 Printer.CurrentX = ((Printer.ScaleWidth - 40) / 3) * 2 + ((Printer.ScaleWidth - 40) / 3 - Printer.TextWidth(Me.MSFlexGrid1.Text)) / 2 Printer.CurrentY = starty Printer.Print Me.MSFlexGrid1.Text Printer.CurrentX = pageleft + Printer.ScaleLeft Printer.CurrentY = Printer.CurrentY + 1 Printer.Line -((Printer.ScaleLeft + Printer.ScaleWidth - pageleft), Printer.CurrentY) Printer.CurrentY = Printer.CurrentY + 1 End If Next i '打印最后一条横线 Printer.CurrentX = Printer.ScaleLeft + pageleft Printer.Line -((Printer.ScaleLeft + Printer.ScaleWidth - pageleft), Printer.CurrentY) endline = Printer.CurrentY '打印四条竖线 Printer.Line (0, startline)-(0, endline) Printer.Line (usewidth / 3, startline)-(usewidth / 3, endline) Printer.Line ((usewidth / 3) * 2, startline)-((usewidth / 3) * 2, endline) Printer.Line (usewidth, startline)-(usewidth, endline) '打印页号 Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(Printer.Page)) / 3 - pageleft Printer.CurrentY = useheight + 3 'Printer.Print Printer.Page Printer.Print " 哈尔滨高新技术开发区" Printer.EndDoc 'EndDoc告诉VISUAL BASIC,程序创建文档结束。VISUAL BASIC应将它发送到物理打印机上打印。 If Err.Number = 0 Then MsgBox "you are successful!", , "" End If End Sub

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧