|
-
Apr 21st, 2005, 01:42 PM
#1
Thread Starter
Lively Member
[SOLVED] TextBox.Lines property
Hey i am trying to simulate a console for my app so i'm using a textbox to show some output information.
I am using following code for displaying info in the textbox:
VB Code:
private lineCount as integer = 0
private sub addLine(byval newline as string)
dim i as integer
if lineCount >= 20
for i = 0 to 20
pInfo.Lines(i)=pInfo.Lines(i+1) ' pInfo is my textbox
next i
pInfo.Lines(20)= newline 'newline is the string i pass to the sub containing new info i need to show.
else
pInfo.Lines(lineCount)=newline
lineCount=lineCount+1
end if
end sub
yet nothing happens as if textbox.lines property were read only , yet i receive no error still my textbox remains unchanged.
I initialised the textbox with property
pInfo.Text = "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
how should i approach this? i was so happy to have discovered .Lines property so i dont have to use string functions, but i feel like i'm missing something.
Last edited by mindloop; Apr 21st, 2005 at 03:45 PM.
Reason: SOLVED
ehmm...
-
Apr 21st, 2005, 02:14 PM
#2
Addicted Member
Re: TextBox.Lines property
just add the lines by appending a new line of text to the current text of the TextBox.
VB Code:
Public Property Lines() As String()
The Lines member of TexBox is an array, so to add lines, you have to resize the array, which is a little odd only to add a line of text to your textbox.
VB Code:
TextBox1.Text += "newlineoftext" + Environment.NewLine
There are no stupid questions, but a whole bunch of dumb sayings !
Save time on database code, try DataLG !
-
Apr 21st, 2005, 02:23 PM
#3
Thread Starter
Lively Member
Re: TextBox.Lines property
Hehe, dont think u got my problem right. i want to avoid scrollbar from appearing. therefor i want to make line no 2 become line no 3 and so on.
adding lines would just fill my textbox and a scrollbar would appear.
i need to handle lines by managing the string array Lines[]. but apparently i cant handle it as a regular string array since i cant replace say Lines[2] value with a new value let's say Lines[3]
i initialised the array with blank lines. my textbox is fixed size therefor i only need to initialise 21 lines that's how much lines it can fit without scrolling.
i dont need to resize the string array. i only need to reuse the defined elements.
-
Apr 21st, 2005, 02:34 PM
#4
Addicted Member
Re: TextBox.Lines property
try this :
VB Code:
Private lineCount As Integer = 0
Private Sub addLine(ByVal newline As String)
Dim asLines As String()
If lineCount >= 20 Then
asLines = TextBox1.Lines
asLines(lineCount Mod 20) = newline
TextBox1.Lines = asLines
Else
TextBox1.Text += newline + Environment.NewLine
End If
lineCount += 1
End Sub
Don't know why the intermediate array 'asLines' is necessary, but without it, the line doesn't get replaced. Anybody knows why?
There are no stupid questions, but a whole bunch of dumb sayings !
Save time on database code, try DataLG !
-
Apr 21st, 2005, 03:44 PM
#5
Thread Starter
Lively Member
Re: TextBox.Lines property
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|