text formating  
Author Message
LynnOoi





PostPosted: Visual Basic General, text formating Top

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.




Visual Basic7  
 
 
nobugz





PostPosted: Visual Basic General, text formating Top

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.



 
 
Moayad Mardini





PostPosted: Visual Basic General, text formating Top

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


 
 
LynnOoi





PostPosted: Visual Basic General, text formating Top

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

 
 
LynnOoi





PostPosted: Visual Basic General, text formating Top

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

 
 
weirdbeardmt





PostPosted: Visual Basic General, text formating Top

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



 
 
LynnOoi





PostPosted: Visual Basic General, text formating Top

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

 
 
LynnOoi





PostPosted: Visual Basic General, text formating Top

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.



 
 
weirdbeardmt





PostPosted: Visual Basic General, text formating Top

It should be txtDisplay1.text.insert

And yes, replace bulletchar with the correct char value.



 
 
LynnOoi





PostPosted: Visual Basic General, text formating Top

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

 
 
LynnOoi





PostPosted: Visual Basic General, text formating Top

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



 
 
weirdbeardmt





PostPosted: Visual Basic General, text formating Top

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)



 
 
LynnOoi





PostPosted: Visual Basic General, text formating Top

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.



 
 
LynnOoi





PostPosted: Visual Basic General, text formating Top

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



 
 
weirdbeardmt





PostPosted: Visual Basic General, text formating Top

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