|
Post by (X) on Jun 9, 2022 12:48:16 GMT 1
I found code that positions the cursor in a multi-line TextBox to the end-of-text and simultaneously brings the end-of-text into view. This way you can have the effect of a down scrolling cursor terminal screen.
See following posts for an even better way...
This is the key piece of code I found. The first line sets the focus to the specified text box control and the second sends a Ctrl-End key sequence which positions the cursor to the end-of-text and brings it into view.
<editbox>.SetFocus SendKeys "^{END}", True
I suppose one could create a procedure called AppendText()... Proc AppendText(tb As TextBox, s$)
'''''''''''''''''''''''''''''''''''''''''''''''''' ' Append text to specified multi-line textbox ' control and automatically bring the appended ' text into view. ' tb.SetFocus tb.text = tb.text & s$ SendKeys "^{END}", True
EndProc
|
|
|
Post by dragonjim on Jun 9, 2022 14:51:27 GMT 1
Nice tip.
Another way of doing this is to use the ScrollCaret method as below
Ocx TextBox tb = "", 10, 10, 400, 40 : tb.MultiLine = True : tb.ScrollBars = 2 tb.Text = "Really long" Do tb.Text = tb.Text & "and still longer..." Until Len(tb.Text) > 400 tb.Text = tb.Text & " and the caret should appear here--->" tb.SelStart = Len(tb.Text) tb.ScrollCaret tb.SetFocus Do : Sleep : Until Me Is Nothing
You should also be able to use the Scroll(RowFromChar,ColFromChar) method but, for some reason, the RowFromChar and ColFromChar both return -1 if the caret position is at the end of the text...will have to look into this to see if this is expected behaviour.
|
|
|
Post by (X) on Jun 9, 2022 17:57:05 GMT 1
Thanks dragonjim!,
This is "ACE"!
I've changed AppendText() to:
Proc P_AppendText(tb As TextBox, s$) '''''''''''''''''''''''''''''''''''''''''''''''''' ' Append text to specified multi-line textbox ' control and automatically bring the appended ' text into view. ' tb.SetFocus tb.Text = tb.Text & s$ tb.SelStart = Len(tb.Text) tb.SelLength = 0 tb.ScrollCaret EndProc
|
|
|
Post by dragonjim on Jun 13, 2022 15:21:35 GMT 1
It appears that RowFromChar and ColFromChar are broken, mainly because the underlying message call using EM_POSFROMCHAR seems not to work as described for textboxes; not only do you get -1 returned if the caret is at the end of the text, but the y-value seems to go no higher than 182. I get the same issues with the User32 library function GetCaretPos.
Hence, I think it is safe to say that RowFromChar and ColFromChar are broken for Textboxes and have only limited use with RichEdit controls.
|
|
|
Post by (X) on Jun 14, 2022 18:23:14 GMT 1
This (taken from GFA Help document) seems to work...
$Library "gfawinx" $Library "UpdateRT" UpdateRuntime ' Patches GfaWin23.Ocx
OpenW 1
Ocx TextBox tb = "", 10, 10, 300, 300 : .MultiLine = True : .ScrollBars = 2 : .BorderStyle = 1
Global Int32 n, tbpos
For n = 0 To Screen.FontCount - 1 tb.Text = tb.Text & Screen.Fonts(n) & ", " Next n
Ocx Command cmd(1) = "Scroll Up", 320, 10, 100, 22 Ocx Command cmd(3) = "Scroll Down", 320, 40, 100, 22 Ocx Command cmd(4) = "Scroll to Caret", 320, 70, 100, 22
Do : Sleep : Until Win_1 Is Nothing
Sub cmd_Click(Index%) tb.SetFocus If Index% = 4 Then tb.ScrollCaret : Exit Sub ~tb.Scroll(0, (Index% - 2) * 3) EndSub
Sub tb_GotFocus tb.SelStart = tbpos EndSub
Sub tb_LostFocus If Not tb Is Nothing Then tbpos = tb.SelStart EndSub
|
|
|
Post by dragonjim on Jun 14, 2022 21:22:07 GMT 1
That will teach me to read the help file properly especially as I wrote that example years ago... In that case, to answer your original query and without having to move the caret, the following code should scroll to the bottom of a textbox: OpenW 1 Ocx TextBox tb = "", 10, 10, 300, 300 : .MultiLine = True : .ScrollBars = 2 : .BorderStyle = 1 Global Int32 n, tbpos
For n = 0 To Screen.FontCount - 1 tb.Text = tb.Text & Screen.Fonts(n) & ", " Next n
Ocx Command cmd = "Scroll to End", 320, 70, 100, 22
Do : Sleep : Until Win_1 Is Nothing
Sub cmd_Click tb.SetFocus Local caretline% = tb.LineFromChar(tb.SelStart) // Line currently containing the caret Local lastline% = tb.LineFromChar(Len(tb.Text)) // The number of the last line of text Local firstchar% = tb.CharFromLine(Len(tb.Text)) // First character in the last line of text Local lastchar% = Len(tb.Text) // Last charcter in the last line of text ~tb.Scroll(lastchar% - firstchar% + 1, lastline% - caretline% + 1) EndSub
Sub tb_GotFocus tb.SelStart = tbpos EndSub
Sub tb_LostFocus If Not tb Is Nothing Then tbpos = tb.SelStart EndSub The code to scroll horizontally may seem redundant but would come in useful if there was a horizontal scroll bar as well.
|
|