I have a textbox control that functions as a log window for my application, and I've successfully made it scroll to the bottom automatically.
Unfortunately the function used gives the window focus (While I don't want that) I've tried using selStart with the textbox length, and I tried using the following API call:
Code:
SendMessage txtLog.hWnd, WMVSCROLL, SBBOTTOM, 0
Is there any other API call or anything that makes it scroll to the bottom without giving focus to it ?
Edit: Just changing the text of the textbox gives it focus apperently, is there any way to prevent this ?
If you add vbCrLf to your log messages already, then you might wish to subtract 2 from the length.
The focus is obviously not given to the textbox as far as I have tried.
I found it now, I had a call in the log script that did frm_log.Show() which triggered it to get focus, I just added a check now if it's already visible and that fixed it.
The only problem remaining is that it tends to scroll back up to the top of the textbox and then back down when I add text (This happens in a very short timeperiod most of the time it's unnoticable) any way around this ?
It never scrolled up by itself. Keep the SelStart always at the end of the text. The SendMessage you are using does not influence the SelStart which is the actual cursor position. If this stays somewhere at the top it could be that it tends to scroll up again.
Strange... you could try finding out if other unwanted events occur, liek keydown, keypress, getfocus, by setting a msgbox instruction into the event handlers.
And I think I just figured out why it would flash back up and then down: When you set the contents the thing gets emptied (Causing the scroll-up) and then it gets filled again.
Shame, shame on me. There are always these blanks I have to type when using the &.
And you know, these days I completely neglect to Set my objevt variables to Nothing, at end of sub, even at Form_Unload(), too.
I hope I find forgiveness, when once in VB heaven.
Bookmarks