-
November 5th, 2009, 10:22 AM
#1
Scrolling to textbox bottom without focus ?
Hey,
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 ?
Thanks for your time, Xeross
-
November 5th, 2009, 12:13 PM
#2
Re: Scrolling to textbox bottom without focus ?
Use this:
Code:
txtLog.Selstart = Len(txtLog.Text)
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.
-
November 5th, 2009, 12:36 PM
#3
Re: Scrolling to textbox bottom without focus ?
It seems just adding text to it gives it focus somehow.
-
November 5th, 2009, 12:38 PM
#4
Re: Scrolling to textbox bottom without focus ?
Code:
With frm_log.txtLog
If .Text <> "" Then
.Text = .Text & vbNewLine
End If
.Text = .Text & "[" & cDay & "/" & UCase(MonthName(Month(Now), True)) & "/" & cYear & "][" & cHour & ":" & cMinute & ":" & cSecond & "] "
.Text = .Text & outStr
Call SendMessage(.hWnd, WMVSCROLL, SBBOTTOM, 0)
End With
Note it also gets focus without the sendMessage.
-
November 5th, 2009, 03:27 PM
#5
Re: Scrolling to textbox bottom without focus ?
I tried this in a form with a TextBox and a button:
Code:
Private Sub Form_Activate()
Command1.SetFocus
Text1.Text = "huhu"
End Sub
Putting text into the box does NOT set the focus to it. It must happen earlier.
-
November 5th, 2009, 03:51 PM
#6
Re: Scrolling to textbox bottom without focus ?
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 ?
Regards, Xeross
-
November 5th, 2009, 03:55 PM
#7
Re: Scrolling to textbox bottom without focus ?
I use a texbox for logging in quite a similar way.
Code:
txtlog.text = textlog.text + newtext$ + vbcrlf
txtLog.Selstart = Len(txtLog.Text)
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.
-
November 5th, 2009, 05:11 PM
#8
Re: Scrolling to textbox bottom without focus ?
I'm using the selStart again, but somehow I still get these jumps to the top though they are almost unnoticable.
-
November 6th, 2009, 12:32 PM
#9
Re: Scrolling to textbox bottom without focus ?
Strange... you could try finding out if other unwanted events occur, liek keydown, keypress, getfocus, by setting a msgbox instruction into the event handlers.
Does the jump occur, when you add the new text?
-
November 6th, 2009, 12:52 PM
#10
Re: Scrolling to textbox bottom without focus ?
It adds when adding new lines, replacing lines, or adding something to the current line.
-
November 6th, 2009, 04:45 PM
#11
Re: Scrolling to textbox bottom without focus ?
Okay. Another method of adding text to the textbox is inserting it at the cursorposition.
Code:
txtlog.Selstart=len(txtlog.text)
txtlog.SelText=NewText
You could try this instead of txtlog.text = txtlog.text + NewText
-
November 6th, 2009, 05:42 PM
#12
Re: Scrolling to textbox bottom without focus ?
That might work.
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.
I'll test it tomorrow. thanks.
-
November 7th, 2009, 02:33 AM
#13
Re: Scrolling to textbox bottom without focus ?
Wof! Bad Wof! using + to concatinate strings. Bad Wof!
-
November 7th, 2009, 04:05 AM
#14
Re: Scrolling to textbox bottom without focus ?
-
November 7th, 2009, 11:31 AM
#15
Re: Scrolling to textbox bottom without focus ?
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.
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
|