Option Explicit |
Dim content As String |
Dim length As Long |
Dim pos As Long |
Private Sub Form_Load() |
'//预先设定要显示的内容 |
content = "静夜思 作者:李白 床前明月光,疑是地上霜。举头望明月,低头思故乡。" |
'//获取内容长度 |
length = Len(content) |
'//label1控件,手动调整,如图所示 |
'//接着需要选择字体大小 |
Set Me .Font = Label1.Font '//方便借用Form.TextHeight方法 |
Dim font_height As Long , font_width As Long , size As Long |
size = Label1.Font.size |
font_height = Me .TextHeight( "床前明月光" ) |
font_width = Me .TextWidth( "床前明月光" ) |
While font_height <= Label1.Height And font_width <= Label1.Width |
size = size + 1 |
Label1.Font.size = size |
font_height = Me .TextHeight( "床前明月光" ) |
font_width = Me .TextWidth( "床前明月光" ) |
Wend |
Label1.Font.size = size - 1 '//选择最合适的字体大小 |
pos = 1 '//从第一个字符开始读取 |
End Sub |
Private Sub Command1_Click() |
Timer1.Interval = 1000 '1000毫秒执行一次 |
End Sub |
Private Sub Timer1_Timer() |
Dim size As Long , temp As String |
'//每次显示5个长度单位的内容 |
size = length - pos '//得到截取的长度大小 |
If size < 4 Then '//当不足5个长度单位时 |
temp = Mid(content, pos, size + 1) |
temp = temp & Mid(content, 1, 4 - size) |
pos = 5 - size |
Else |
temp = Mid(content, pos, 5) |
pos = pos + 5 |
End If |
Label1.Caption = temp '//把截取的文本内容显示出来 |
End Sub |
by: 发表于:2017-12-01 14:56:16 顶(1) | 踩(1) 回复
??
回复评论