mutil line txt box

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

Hello

For a VB novice can anyone help me with the following simple idea.

All I've got on my form is a Textbox, (mulitline = true) and a button.

When I click the button I will have some simple lines of text to be
displayed. How do I have...

Dim addLine As String = "Next Line"
Dim addLine As String = "Another Line"


TextBox1.Text = "Line one"
then the next line display Next Line
and the next display Another Line

What is the newline char? \n
 
If I write this..

TextBox1.Text = "Line one"vbCrLf
TextBox1.text "more Text"

It just overwrites the top line, with the next line, then the next.

I'm tring to display them on seperate line
1) Line one
2) more Text
3) something else

Or am i doing this wrong?
 
Try this...

Me.TextBox1.Text += "Line One" & vbCrLf
Me.TextBox1.Text += "Line Two" & vbCrLf

That will give you

Line One
Line Two
 
Jason said:
All I've got on my form is a Textbox, (mulitline = true) and a button.

When I click the button I will have some simple lines of text to be
displayed. How do I have...

Dim addLine As String = "Next Line"
Dim addLine As String = "Another Line"


TextBox1.Text = "Line one"
then the next line display Next Line
and the next display Another Line


\\\
Me.TextBox1.Text = _
"Line 1" & ControlChars.NewLine & _
"Line 2" & ControlChars.NewLine & _
"Line 3"
///
 
jvb said:
Me.TextBox1.Text += "Line One" & vbCrLf
Me.TextBox1.Text += "Line Two" & vbCrLf

Mhm... I suggest to use '&=' instead of '+=' to concatenate strings.
 
One more quick and easy question.
Me.TextBox1.Text += "Line Two" & vbCrLf

How can I make that line BOLD?

Thanks again
 
Is there any reason that &= is better than +=? I have always used the
+. Am I going against convention?
 
You can't in a standard text box.
You'll need to use the rich text box ... different game altogether!
_______________________________
The Grim Reaper
 
Anyone...

when I run this
Me.TextBox1.Text += "Line One" & vbCrLf
Me.TextBox1.Text += "Line Two" & vbCrLf

I get...

Line One
Line Two

But both lines are selected, is that supposed to be that way? How can I get
rid of the highlighting?
 
I was going to say "you're going against convention!".... but then I checked
my local MSDN and found;

&=
Concatenates a String expression to a String variable or property and
assigns the result to the variable or property.

+=
Adds the value of a numeric expression to the value of a numeric variable or
property and assigns the result to the variable or property. Can also be
used to concatenate a String expression to a String variable or property and
assign the result to the variable or property.

So there you go!
____________________________________
The Grim Reaper
 
The Grim Reaper said:
I was going to say "you're going against convention!".... but then I
checked my local MSDN and found;

&=
Concatenates a String expression to a String variable or property and
assigns the result to the variable or property.

+=
Adds the value of a numeric expression to the value of a numeric variable
or property and assigns the result to the variable or property. Can also
be used to concatenate a String expression to a String variable or
property and assign the result to the variable or property.

Mhm... But I remember the documentation for '&' recommends to use '&' for
string concatenation instead of '+'.
 
Me.TextBox1.SelectionStart = 0
Me.TextBox1.SelectionLength = 0

(I haven't had cause to use them much before, so experiment with what you
want to achieve)
___________________________________
The Grim Reaper
 
Hi,

Try this one with option strict off and be happy

dim a as string = "1"
a += 1

Cor
 
Thanks

Shouldn't that be in the properties of the Text Box?

Also how do you make a one line of text bold?


Me.TextBox1.Text += "Line One" & vbCrLf
Me.TextBox1.Text += "Line Two" & vbCrLf
 
To have only one line bold, you have to use a RichTextBox. Select the
text you want and execute this line:

rtb.SelectionFont = New Font(rtb.Font, FontStyle.Bold)

where rtb is the RichTextBox.
 
If I've got this

Me.RichTextBox1.Text = "In Rich Text Box"
Me.RichTextBox1.Text &= "Line two" & vbCrLf
How do I make the second line BOLD?
 
Back
Top