Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a textbox and after pasting a Url from the clipboard or with Ctrl+V in my Textbox I want my Textbox.text to start on a new line everytime after pasting the Url but What is the correct VB code for this. My Textbox is set to multiline.

Here is an example of what I want it to be:
Imgur: The magic of the Internet[^]

Thanks for helping me

What I have tried:

Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
    'TextBox2.AppendText(Environment.NewLine)
    'TextBox2.Text &= ControlChars.CrLf & newText
    'TextBox2.AppendText("your new text" & Environment.NewLine)

    'TextBox2.Text = "" + vbCrLf

    'TextBox2.Text = "line_one" & vbCrLf & "line_two"
    'TextBox2.Text += Environment.NewLine
    'TextBox2.Text = TextBox2.Text & ControlChars.NewLine

    'TextBox2.Text = "This is a test"
    'TextBox2.Text = TextBox2.Text & ControlChars.NewLine & "This is line 2"

    'TextBox2.Text.Replace("\n", Environment.NewLine)
    'TextBox2.Text = TextBox2.Text.Replace(Environment.NewLine, "<br \>", "\ n")
    'Dim a As String = TextBox2.Text
    'TextBox2.Text += TextBox2.Text.Replace("\n", Environment.NewLine)
    TextBox2.Text = TextBox2.Text.Replace("\n", Environment.NewLine)
End Sub
Posted
Updated 14-Apr-22 9:53am
v3
Comments
OriginalGriff 14-Apr-22 1:50am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?

That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!

Use the "Improve question" widget to edit your question and provide better information.

1 solution

If i understant you well, you want to catch "OnPaste" event. So, i'd suggest to use Control.KeyDown Event (System.Windows.Forms) | Microsoft Docs[^]

VB.NET
Private Sub textBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) _
      Handles textBox1.KeyDown
    Dim IsCtrlVUsed As Boolean = e.Modifiers = Keys.Control And e.KeyCode = Keys.V;
    If IsCtrlVUsed Then
      'use your logic
    End If

End Sub


Note: Not tested but it should do the job!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900