How do I add a newline to a windows-forms TextBox?

后端 未结 14 429
温柔的废话
温柔的废话 2021-01-01 09:37

I am trying to add a line of text to a TextBox component in VB.net, but I cannot figure out for the life of me how to force a new line. Right now it just adds onto what I ha

相关标签:
14条回答
  • 2021-01-01 10:20

    Use the text below!

    TextBox1.Text = "This is a test"
    TextBox1.Text = TextBox1.Text & ControlChars.Newline & "This is line 2"
    

    The controlchars.Newline will automatically put "This is line 2" to the next line.

    0 讨论(0)
  • 2021-01-01 10:22

    Have you set AcceptsReturn property to true?

    0 讨论(0)
  • 2021-01-01 10:22

    Have you tried something like:

    textbox.text = "text" & system.environment.newline & "some more text"

    0 讨论(0)
  • 2021-01-01 10:24

    First you have to set the MultiLine property of the TextBox to true so that it supports multiple lines.

    Then you just use Environment.NewLine to get the newline character combination.

    0 讨论(0)
  • 2021-01-01 10:24

    Quickie test code for WinForms in VB:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        Dim Newline As String
        Newline = System.Environment.NewLine
    
        TextBox1.Text = "This is a test"
        TextBox1.Text = TextBox1.Text & Newline & "This is line 2"
    
    End Sub
    
    0 讨论(0)
  • 2021-01-01 10:25

    make sure you textbox is set for multiline then you wont need any extra dims vbnewline will work just fine

    0 讨论(0)
提交回复
热议问题