text formating

Hi,

i would like to ask whether can i format the text in textbox in such a way that whenever there is a bullet, it will display it in a newline.

the textbox data is retrieve from a database in the same column.




Answer this question

text formating

  • Brian Westover

    Something like this... I haven't tested it so it'll need some tweaking. And you'll need to find the char code for a bullet.

     

    dim start as integer = 0

    do while txtTextbox.text.indexof("bulletchar", start) >-1 andalso txtTextbox.text.lastindexof("bulletchar") <> txtTextbox.text.indexof("bulletchar", start)

    txtTextbox.insert(start-1,Environment.Newline)

    start=start+1

    loop



  • Jeroen Bransen - J-Thread

    Actually, sorry, there's a heaps more efficient way of doing this. I should switch my brain on.

    txtDisplay1.text = txtDisplay1.text.replace("bulletchar","bulletchar" & environment.newline)



  • kiwishane

    Is it i must replace the word "bulletchar" with the bullet's code in Ascii table

  • jannell

    How do i write my If else statement in order to make it move to newline when it met a bullet.

  • MattH6

    Try using a RichTextBox. You'll need to generate text in the RTF format if it is not already in that format in the database.



  • Andriy Karasyov

    i am sorry. i am very new in vb.net. so may i know how to check whether it is in the RTF format or not

  • AccTech

    For multi-line textbox :
    • Set TextBox.Multiline property to True
    • To add a new line, use Environment.NewLine


  • Chris_Bond

    I am sorry to ask so many questions. I have include the code in my program. however, nothing happens to the output. Everything just looks the same as before.

    May i know where should i include the code



  • dczyz

    i have put the code in my program already but there is an error in the statement:

    txtDisplay1.insert(start - 1, Environment.NewLine)

    It says that textbox do not have insert property.



  • piip

    Hi, sorry I wasn't clear. It should be:

    Private Sub txtDisplay1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDisplay1.TextChanged

    txtDisplay1.Text = txtDisplay1.Text.Replace("."c, ". " & Environment.NewLine)

    End Sub

    You also hadn't declared the characters correctly, as it would have been looking for a string "95". If you're using a full-stop now, it should work OK as above. However, you will want to be careful doing this in the text-changed event. What is it you're trying to do



  • SOHI

    ok.. thanks a lot. I will try it.

  • Mike_63

    Is okay. DOnt't have to say sorry because i am shy. i am so new in vb.net and i have so many questions.

    ok.. i will try to include the code in my program. By the way, thanks a lot.



  • Joy19101

    It should be txtDisplay1.text.insert

    And yes, replace bulletchar with the correct char value.



  • Darwinsmom

    i have tried to use the codes but it doesn't work as well. is it my programing code got problem actually i could not find the ASCII code for bullet, therefore i use the code for fullstop. however, it does not work also. i attached my code for you to have a look.

    Private Sub txtDisplay1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDisplay1.TextChanged

    Dim start As Integer = 0

    Do While txtDisplay1.Text.IndexOf("95", start) > -1 AndAlso txtDisplay1.Text.LastIndexOf("95") <> txtDisplay1.Text.IndexOf("95", start)

    txtDisplay1.Text = txtDisplay1.Text.Replace("95", "95" & Environment.NewLine)

    start = start + 1

    Loop

    End Sub



  • text formating