也不是不可以实现,只不过复杂一点而已,具体看下面代码。不过在需要换行等情况下的文本显示,还是建议用RichTextBox开启只读属性比较省心、比较合适。
成都创新互联-专业网站定制、快速模板网站建设、高性价比龙华网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式龙华网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖龙华地区。费用合理售后完善,十载实体公司更值得信赖。
Private Sub AutoNextRow()
'获取ListBox行集合文本
Dim length As Integer = (ListBox1.Items.Count - 1)
Dim items(length) As String '行文本数组
For i As Integer = 0 To length
items(i) = ListBox1.Items(i).ToString
Next
'处理ListBox换行
ListBox1.Items.Clear() '清空行内容
Using g As Graphics = Graphics.FromHwnd(ListBox1.Handle)
Dim result As New List(Of Object)
Dim w As Single = ListBox1.ClientSize.Width
Dim sf As SizeF, str As StringBuilder
For Each s As String In items
str = New StringBuilder
For i As Integer = 0 To (s.Length - 1)
sf = g.MeasureString(str.ToString s(i), ListBox1.Font)
If sf.Width w Then
result.Add(str.ToString)
str = New StringBuilder
End If
str.Append(s(i))
If i = s.Length - 1 Then result.Add(str.ToString)
Next
Next
ListBox1.Items.AddRange(result.ToArray) '填充行内容
End Using
End Sub
Dim MultiString as String‘有许多行的字符串Dim StrArray() as String'字符串类型的一维数组StrArray=Split(MultiString,VbCrlf)'用换行符分割字符串
1.把ListBox的MultiSelect的属性设为2
2.对滚动条的Scroll事件进行编写
(Added
Attachment)