Link to home
Start Free TrialLog in
Avatar of kplonk
kplonk

asked on

how to do a strange scrool

i have a text box an in it is more text then can fit, so i use the vertical scrool bar to scrol, i want to use the up and down keys to scrol up and down one line at a time any ideas.
Avatar of Erick37
Erick37
Flag of United States of America image

Set the ScrollBars property of the TextBox to 3 - Both, or 2 - Vertical.
Then the up and down keys will move the caret up and down one line and the scroll bars will reflect the change.
Avatar of kplonk
kplonk

ASKER

no no you are missing the point. I do not want to use the curser in the box becaus if i am on the top line of the box an i wan to scrol one line off the bottom then i will need to press the down arrow 11 times, get the idea. Thanks anyway, reguards kieran.
Ther is a SendMessage parameter that can be used to scroll the box like you want, but I can't remember it.
You could try this...

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    Const EM_LINESCROLL = &HB6
    Select Case KeyCode
    Case vbKeyDown: SendMessage Text1.hWnd, EM_LINESCROLL, 0, ByVal 1
    Case vbKeyUp:   SendMessage Text1.hWnd, EM_LINESCROLL, 0, ByVal -1
    End Select
End Sub

Ross
Yep, that's the one.
ASKER CERTIFIED SOLUTION
Avatar of WatsonR
WatsonR

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad you posted, because I lost this bit of code a couple of weeks ago! Now we just have to wait for kplonk to come back and accept it.
kplonk,

if you accept this answer, may I suggest you accept KDivad's post, as it was his information that led to my post.

Regards,
Ross
But what does the code do?
The TextBox already scrolls with the up/down key.
Ohhh,
Now I get it.
The caret stays at the top!   :-)
Well yes, but if your text box is, say, 5 lines high, and the carat is in line one, I understood that the desired effect of a down arrow was to scroll the display by one line (thus having the 2nd line at the top) as opposed to having the carat move to line 2. Therefore, if you wanted to see line 6, you pressed down arrow once as opposed to 6 times.
WatsonR,
Accept mine instead of yours? Or both?

Erick37,
As you've probably figured out, this code sends a message to the textbox telling it to move it's scrollbars just as they would if you were to use the mouse on the scrollbars.

To all,
I THINK passing the numbers in the third parameter do a horizontal scroll.

Later,
KDivad

I was being magnanamous and suggesting that, without your post, writing a solution would have taken longer - and thereby suggesting that kplonk should accept your post as the answer.

Ross
I appreciate that, I just wasn't sure since it came after you posted an answer.

Later,
KDivad Leahcim
Avatar of kplonk

ASKER

sorted mate
Nice gesture anyway, WatsonR. You did give the code, though.

Later,