如果字符超过25,如何使用新行

时间:2014-10-22 04:04:25

标签: vb.net

labelsample.text = abcdefghijklmnopqrstuvwxyz123456789

If samplelabel.textlength = 25 then
   'How to move it to nextline?

输出应该是这样的:

  abcdefghijklmnopqrstuvwx    
  z123456789

1 个答案:

答案 0 :(得分:2)

使用MOD运算符决定何时插入回车符。

Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim sb As New System.Text.StringBuilder
        Dim sampleText As String = "abcdefghijklmnopqrstuvwxyz123456789"
        For i As Integer = 1 To sampleText.Length
            sb.Append(sampleText(i - 1))
            If i Mod 25 = 0 Then
                sb.AppendLine()
            End If
        Next
        Label1.Text = sb.ToString
    End Sub
End Class