-
Textbox Add Line...
I have a textbox which is constantly updated with new information. I update
the textbox with the following line:
Text1.Text = Text1.Text & strNewLine
This method is very poor. It causes screen flickering, since I'm reloading
the textbox everytime. I'm even doing a 'LockWindowUpdate' to reduce
flicker but that doesn't seem to help.
Is there a way to simply add lines to the textbox without using the above
line of code. The ListBox allow you to use AddItem, this is basically what
I'm looking for with the textbox.
Any help is appreciated...
-
Re: Textbox Add Line...
Hi Brian --
> I have a textbox which is constantly updated with new information. I update
> the textbox with the following line:
> Text1.Text = Text1.Text & strNewLine
>
> This method is very poor. It causes screen flickering, since I'm reloading
> the textbox everytime. I'm even doing a 'LockWindowUpdate' to reduce
> flicker but that doesn't seem to help.
>
> Is there a way to simply add lines to the textbox without using the above
> line of code. The ListBox allow you to use AddItem, this is basically what
> I'm looking for with the textbox.
Yep. Do this, instead:
Text1.SelStart = Len(Text1.Text)
Text1.SelText = strNewLine
Later... Karl
--
http://www.mvps.org/vb
-
Re: Textbox Add Line...
Thanks Karl
The textbox still seems to flicker, do you know how I might fix this ?
Brian
Karl E. Peterson <karl@mvps.org> wrote in message
news:39662b72$1@news.devx.com...
> Hi Brian --
>
> > I have a textbox which is constantly updated with new information. I
update
> > the textbox with the following line:
> > Text1.Text = Text1.Text & strNewLine
> >
> > This method is very poor. It causes screen flickering, since I'm
reloading
> > the textbox everytime. I'm even doing a 'LockWindowUpdate' to reduce
> > flicker but that doesn't seem to help.
> >
> > Is there a way to simply add lines to the textbox without using the
above
> > line of code. The ListBox allow you to use AddItem, this is basically
what
> > I'm looking for with the textbox.
>
> Yep. Do this, instead:
>
> Text1.SelStart = Len(Text1.Text)
> Text1.SelText = strNewLine
>
> Later... Karl
> --
> http://www.mvps.org/vb
>
>
>
-
Re: Textbox Add Line...
I think a text box is the wrong tool for this kind of job, try the listbox or the listview controls.
Also you may want to consider caching the information before you write it, iow, make an array <or collection if you are really lazy,
and dun care about memory or optimization, )> and when either a time period elapses <like 5 seconds>, the array hits critical mass
<?? 100 notifications (you would always leave your array ubound at the critical mass, and never erase it, just keep a counter of
where you are at otherwise, redims take there toll very quickly)>, or the user pushes a "refresh" button, you can flush the new
notifications to the text box/list box, cutting down on the amount of times per second you are writing to the slow UI control.
Oren
"Brian Patrick" <bpatrick@provide.net> wrote in message news:39664584@news.devx.com...
> Thanks Karl
>
> The textbox still seems to flicker, do you know how I might fix this ?
>
> Brian
>
>
> Karl E. Peterson <karl@mvps.org> wrote in message
> news:39662b72$1@news.devx.com...
> > Hi Brian --
> >
> > > I have a textbox which is constantly updated with new information. I
> update
> > > the textbox with the following line:
> > > Text1.Text = Text1.Text & strNewLine
> > >
> > > This method is very poor. It causes screen flickering, since I'm
> reloading
> > > the textbox everytime. I'm even doing a 'LockWindowUpdate' to reduce
> > > flicker but that doesn't seem to help.
> > >
> > > Is there a way to simply add lines to the textbox without using the
> above
> > > line of code. The ListBox allow you to use AddItem, this is basically
> what
> > > I'm looking for with the textbox.
> >
> > Yep. Do this, instead:
> >
> > Text1.SelStart = Len(Text1.Text)
> > Text1.SelText = strNewLine
> >
> > Later... Karl
> > --
> > http://www.mvps.org/vb
> >
> >
> >
>
>
-
Re: Textbox Add Line...
Hi Brian --
> The textbox still seems to flicker, do you know how I might fix this ?
Dunno what to say. No flicker here with this code:
Private Sub Timer1_Timer()
Text1.SelStart = Len(Text1.Text)
Text1.SelText = Format(Now, "0.0000000000") & vbCrLf
End Sub
(Timer set to 200.) Are you moving the cursor otherwise? Maybe the listbox is a
better idea (as Oren suggests). Hard to say. You won't get a textbox to perform any
smoother than this.
Sorry... Karl
--
http://www.mvps.org/vb
-
Re: Textbox Add Line...
Brian -
> The textbox still seems to flicker, do you know how I might fix this ?
>
If you don't need to use a textbox then you might try this hack that I
use. I use a PictureBox to display the lines of text instead of a
textbox. The PictureBox doesn't seem to flicker the way a label or
a textbox does. In this example you can paste the following code
into a new form. The form needs a timer and picturebox with the
default names. There are some drawbacks such as no
wordwrapping, and no scrolling so if you need those capabilities
you can modify the code to save the text to a public variable, file,
or invisible textbox.
Hope it helps,
Jim Edgar
' Begin paste
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Call UpdatePic(Picture1, Format(Now, "0.0000000000"))
End Sub
Sub UpdatePic(pic As PictureBox, sText As String)
' This can be a module level variable and it can
' be dimensioned during form load in which case
' you will use UBound(Buffer) - 1 in the loops.
Static Buffer() As String
' If Buffer() is a module level variable then the
' following only needs to be done during
' form_load.
Dim iLineCnt As Integer, lLineHgt As Long
' Determine the number of lines that
'the PictureBox can hold.
lLineHgt = pic.CurrentY
pic.Print " "
lLineHgt = pic.CurrentY - lLineHgt
iLineCnt = (pic.ScaleHeight \ lLineHgt) - 1
' Reinitialize the buffer
ReDim Preserve Buffer(iLineCnt)
Dim bRedraw As Boolean, sbuff As String
Dim iCnt As Integer
For iCnt = 0 To iLineCnt - 1
Buffer(iCnt) = Buffer(iCnt + 1)
Next
Buffer(iLineCnt) = sText
' Clear the PictureBox
With pic
bRedraw = .AutoRedraw
' Important to turn on AutoRedraw or the
' picturebox won't display the new text.
.AutoRedraw = True
.Cls
End With
' If there is enough room in the PictureBox
' then print to it.
If iLineCnt > 0 Then
For iCnt = 0 To iLineCnt
If Buffer(iCnt) <> "" Then
pic.Print Buffer(iCnt)
End If
Next
End If
' Reset the autoredraw
pic.AutoRedraw = bRedraw
End Sub
' End paste
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks