初学请教!关于在PICTUREBOX中用VScroll控制长文本的问题?谢谢
初学请教!
pic2在pic1中,vscroll在frm中用于控制pic2的滚动,现在pic2中用print方法输入长文本(记录型的,不定长),现在的问题是pic2的大小不能随文本的变化而变化(自动大小已设置),即使能滚动也不能滚动(一滚动文本就消失了)!谢谢
[解决办法]
用两个PictureBox控件,首先在窗体添加1个PictureBox控件Picture1,然后在Picture1中间用鼠标加载另1个PictureBox控件Picture2.
在窗体添加剂个HScroll控件于窗体或Picture1内,调整Picture2的Height.
注意Picture2的属性AutoRedraw设置为True,以保证Picture2移动后重画.
代码如下:
Option Explicit
Dim sj As String
Dim l As Integer
Private Sub Command1_Click()
sj = "初学请教!pic2在pic1中 , vscroll在frm中用于控制pic2的滚动, 现在pic2中用print方法输入长文本(记录型的, 不定长), 现在的问题是pic2的大小不能随文本的变化而变化(自动大小已设置), 即使能滚动也不能滚动(一滚动文本就消失了)!谢谢 "
sj = sj + sj
l = Len(sj)
Text1 = l
If l < 210 Then
sj = sj
Picture2.Print sj
Picture2.Width = l * 145 '倍率可调整
ElseIf l > = 210 Then '其中文本字符号长度需做文本换行调整,代码需修改以适合更长的文本
sj = Left(sj, 210) & vbNewLine & Right(sj, l - 210)
Picture2.Width = 210 * 145 '倍率可调整
Picture2.Print sj
End If
End Sub
Private Sub Form_Load()
Me.Height = 11295
Me.Width = 15360
Picture1.Width = Me.Width - 400
Picture2.Width = Picture1.Width * 2.1 '倍率可调整
Picture2.AutoRedraw = True
HScroll1.SmallChange = 100
End Sub
Private Sub HScroll1_Change()
Picture2.Left = -HScroll1 * 1.4 / 2.8 '倍率需调整
End Sub
[解决办法]
调整Picture控件的高度和宽度也不是好办法,有上限的,而且效率低。不如在滚动时重新绘制文本。
[解决办法]
Private Sub Picture1_Paint()
'或者放在其他print之后picture大小改变之后的地方
VScroll1.Max = (Picture1.Height - Me.ScaleHeight) / 200
VScroll1.LargeChange = VScroll1.Max / 10
VScroll1.ZOrder
HScroll1.Max = (Picture1.width - Me.Scalewidth) / 200
HScroll1.LargeChange = HScroll1.Max / 10
HScroll1.ZOrder
End Sub
Private Sub VScroll1_Change()
Picture1.Top = 0 - VScroll1.Value * 200
Picture1.left = 0 - HScroll1.Value * 200
End Sub
[解决办法]
Const MAXSTRINGLEN = 10000
Const MAXROWLEN = 50
Dim rownum As Integer, str1 As String
Private Sub Form_Load()
Dim i As Integer
For i = 0 To MAXSTRINGLEN
str1 = str1 + Chr(Int(Rnd() * 128))
If i Mod MAXROWLEN = 0 Then
str1 = str1 + vbCrLf
rownum = rownum + 1
End If
Next
Picture1.Width = TextWidth( "a ") * MAXROWLEN
VScroll1.Left = Picture1.Left + Picture1.Width
VScroll1.Top = Picture1.Top
VScroll1.Height = Picture1.Height - 40
VScroll1.Min = 0
VScroll1.Max = rownum
End Sub
Private Sub VScroll1_Change()
Picture1.Cls
Picture1.Print Mid(str1, VScroll1.Value * (MAXROWLEN + 2) + 1, (MAXROWLEN + 2) * (Picture1.ScaleHeight \ TextHeight( "a ")))
End Sub