Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locking text box auto scroll?

Status
Not open for further replies.

adi316

Programmer
Sep 10, 2002
35
0
0
CA
is it possible to stop a text box from auto scrolling up when something is added to it?

what i do is txtbox = txtbox + newtext and it scrolls up, and then i have to scroll it back down with txtbox.SelStart=Len(txtbox). considering that i am logging data from the serial port into this text box, and i get one char at a time this causes enormous ammounts of screen flickering, and is simply unacceptable. is there any way around it? TIA
 
Try this:

Private Const EM_GETFIRSTVISIBLELINE = &HCE
Private Const EM_LINESCROLL = &HB6
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Private Sub Command1_Click()
Dim lngTopLine As Long
lngTopLine = SendMessage(Text1.hwnd, EM_GETFIRSTVISIBLELINE, 0, 0)
Text1.Text = Text1.Text & strStuffToAdd
Call SendMessage(Text1.hwnd, EM_LINESCROLL, 0, lngTopLine)
End Sub
 
Why do you need to stop the text box scrolling?

If you don't want it to scroll then do you need Multiline = true?

What do you do with the text after reading the port?

If you want both scrolling and multiline then perhaps a simple solution would be to use 2 text boxes.

Display your text as it comes in from the port in a visible single line text box but also add it to an invisible multiline text box.

At the end of the process, if you want to see the content of the multiline box, make it visible in the click event of the single line box.

If you see what I mean???
 
thanks for the replys

ok perhaps i dindnt explain in detail enough what i am doing. i need a multline txtbox because i got a two way terminal basically and i need the user to be able to scroll back to whatever point they want at any time. now when stuff comes in it gets added to the bottom of the txt box, but as soon as that happens the scroll bar goes to the top and i have to return it to the bottom using selstart. that is why i wanted to lock it so it doesnt go up once new data comes in.
 
My code should do the trick.

'Place this in your sub before adding the text:
Dim lngTopLine As Long
lngTopLine = SendMessage(Text1.hwnd, EM_GETFIRSTVISIBLELINE, 0, 0)


'and this after:
Call SendMessage(Text1.hwnd, EM_LINESCROLL, 0, lngTopLine)



 
DrJavaJoe using ur code stuff gets added to the window, the scrollbar still goes to the 1st line but then comes up to the last place it was not to all the way down to the bottom. so it is the same as using selstart but it doenst scroll all the way down, which is not what i need.(i have to go back to the bottom not in the middle)

the bottom line is that i need to stop the scroll bar from going up at all when i do Log = Log + newtext. Maybe this can be done by adding the text to the window in a different way?!? i just cant figure it out, i am hoping some can please help. thanks!
 
'I see change to EM_GETLINECOUNT and that should do it.


Option Explicit
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINESCROLL = &HB6
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Private Sub Command1_Click()
Dim lngTopLine As Long
lngTopLine = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
Text1.Text = Text1.Text & strStuffToAdd
Call SendMessage(Text1.hwnd, EM_LINESCROLL, 0, lngTopLine)
End Sub
 
DrJavaJoe
That works but it does the same thing as txtbox.SelStart=Len(txtbox), still scrolls up and than back down.

i am beginning to think there is no way to eliminate the screen flikering, its horrible and im running out of ideas.

thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top