首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

显示不完的文字用半个省约号表示.该怎么解决

2012-02-14 
显示不完的文字用半个省约号表示.Label,Text,怎么用让显示不完的文字用半个省约号表示.比如显示示例文字1

显示不完的文字用半个省约号表示.
Label,Text,怎么用让显示不完的文字用半个省约号表示.

比如显示"示例文字12345"

Label设置长度只有4个字长,刚显示"示例文..."

有什么API实现呀.谢谢

[解决办法]

VB code
Option ExplicitPrivate Sub Form_Load()Dim s As String * 4s = "12345"Label1.Caption = s & "..."End Sub
[解决办法]
VB code
Option ExplicitFunction FormatText(ByVal Text As String, ByVal Length As Long) As String    If Len(Text) <= Length Then        FormatText = Text    Else        FormatText = Left$(Text, Length - 1) & "…"    End IfEnd FunctionPrivate Sub Form_Load()    Label1 = FormatText("示例文字12345", 4)End Sub
[解决办法]
这个还要API?
VB code
If Len(Label1.Caption) > 4 Then    Label1.Caption = Left(Label1.Caption, 4) & "…"End If
[解决办法]
用API可以,DrawText函数,其中参数加上xxx or DT_SINGLELINE or DT_END_ELLIPSIS or DT_PATH_ELLIPSIS即可。
[解决办法]
Function FormatText(ByVal Text As String, ByVal Length As Long) As String
If LenB(strconv(Text,vbFromUnicode)) <= Length Then
FormatText = Text
Else
FormatText = strconv(LeftB(strconv(Text,vbFromUnicode), Length - 2),vbUnicode) & "…"
End If
End Function

Private Sub Form_Load()
Label1 = FormatText("示例文字12345", 8)
End Sub

热点排行