[Solved] Move scrollbar to show text using code
[Solved] Move scrollbar to show text using code
Hi to all.
I have made one dialog. In one page of dialog i want to show some long text.
I want to scroll down or up to read the text using a ScrollBar and with Basic code.
I tried to use TextFiled to do that but when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code.
I tried to use Label but there is no scrollbar on that control.
Is there a better way to do that?
Thanks.
I have made one dialog. In one page of dialog i want to show some long text.
I want to scroll down or up to read the text using a ScrollBar and with Basic code.
I tried to use TextFiled to do that but when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code.
I tried to use Label but there is no scrollbar on that control.
Is there a better way to do that?
Thanks.
Last edited by Jimmy2768 on Sat Jan 22, 2022 8:16 pm, edited 1 time in total.
Open Office 4.1.9
MX Linux 19.4 - Windows 7
MX Linux 19.4 - Windows 7
Re: Move scrollbar to show text using code
If you set the textfield to read only then the cursor will appear but the contents can't be edited.
You can use a listbox and set that to read only.
You can use a listbox and set that to read only.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Move scrollbar to show text using code
If you use a listbox you can scroll by using makevisible
Code: Select all
dlg.getcontrol("ListBox1").makevisible 8 'ensures item 8 is visible
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Move scrollbar to show text using code
Find attached a sample file using this code:
Code: Select all
global oDialog1 as Object
global otxtVerticalScrollbar as Object
Sub Start_Textfield
DialogLibraries.loadLibrary("Standard")
oDialog1 = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
otxtVerticalScrollbar = oDialog1.getcontrol("txtVerticalScrollbar")
otxtVerticalScrollbar.Text = "Hi to all. I have made one dialog. In one page of dialog i want to show some long text."_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that?"_
& "Hi to all. I have made one dialog. In one page of dialog i want to show some long text."_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that?"_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that?"_
& "Hi to all. I have made one dialog. In one page of dialog i want to show some long text."_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that? Thanks."_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that?"_
& "Hi to all. I have made one dialog. In one page of dialog i want to show some long text."_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that?"_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that?"_
& "Hi to all. I have made one dialog. In one page of dialog i want to show some long text."_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that? Thanks."_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that?"_
& "Hi to all. I have made one dialog. In one page of dialog i want to show some long text."_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that?"_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that?"_
& "Hi to all. I have made one dialog. In one page of dialog i want to show some long text."_
& "I want to scroll down or up to read the text using a ScrollBar and with Basic code.I tried to use TextFiled to do that but"_
& "when the control gets focus a cursor appears. Also i don't see any way to move the vertical scroll bar with code."_
& "I tried to use Label but there is no scrollbar on that control. Is there a better way to do that? Thanks."
oDialog1.execute
End Sub
Sub Scroll (event)
dim nAction as integer
nAction = event.Source.Model.tag
oACC = otxtVerticalScrollbar.AccessibleContext.getAccessibleChild(1)
oScrollbar = oACC.AccessibleContext
oScrollbar.doAccessibleAction(nAction)
'0 decrementLine
'1 incrementLine
'2 decrementBlock
'3 incrementBlock
'doAccessibleAction ( nIndex as long )
'for i = 0 to oScrollbar.getAccessibleActionCount - 1
'oAAction = oScrollbar.getAccessibleActionDescription(i)
'xray oAAction
'next i
end sub
- Attachments
-
- VSCB.ods
- (11.92 KiB) Downloaded 165 times
- MMove 1.0.6
- Extension for easy, exact positioning of shapes, pictures, controls, frames ...
- my current system
- Windows 10 AOO, LOLinux Mint AOO, LO
Re: Move scrollbar to show text using code
Thanks for suggestions guys.
Especially thank you “F3K Total”. Excellent work with sample attached file to.
Perfect.
Especially thank you “F3K Total”. Excellent work with sample attached file to.
Perfect.
Open Office 4.1.9
MX Linux 19.4 - Windows 7
MX Linux 19.4 - Windows 7
Re: [Solved] Move scrollbar to show text using code
Attached is the Listbox version if anyone visiting the thread in future wants it...
I borrowed F3K Total's command buttons. There may be a more efficient way to code the next and previous scroll items.
I borrowed F3K Total's command buttons. There may be a more efficient way to code the next and previous scroll items.
- Attachments
-
- listbox.odt
- (13.05 KiB) Downloaded 149 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Solved] Move scrollbar to show text using code
Thanks JeJe.
Useful and without cursor if every line has predefined short length, else an unwanted horizontal scroll bar appears.
Useful and without cursor if every line has predefined short length, else an unwanted horizontal scroll bar appears.
Open Office 4.1.9
MX Linux 19.4 - Windows 7
MX Linux 19.4 - Windows 7
Re: [Solved] Move scrollbar to show text using code
Yeah, you can get round that by reading the lines off a hidden textbox. Borrowing F3K Total's string...
Edit: I didn't do this, but if the textbox is made the same width as the listbox and both have or don't have a vertical scrollbar then they match exactly for me.
Edit: I didn't do this, but if the textbox is made the same width as the listbox and both have or don't have a vertical scrollbar then they match exactly for me.
- Attachments
-
- listbox2.odt
- (13.05 KiB) Downloaded 137 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Solved] Move scrollbar to show text using code
Excellent JeJe
Works very well. On version Apache 4.1.9
I tried on different versions of OpenOffice for compatibility issues and found that i doesn't work in versions prior to 4.1.0.4. The Line lba.getaccessiblechild(i).getlocation.y gives wrong big values so in every step it jumps some lines and moving scrollbar upwards doesn't work at all.
Works very well. On version Apache 4.1.9
I tried on different versions of OpenOffice for compatibility issues and found that i doesn't work in versions prior to 4.1.0.4. The Line lba.getaccessiblechild(i).getlocation.y gives wrong big values so in every step it jumps some lines and moving scrollbar upwards doesn't work at all.
Open Office 4.1.9
MX Linux 19.4 - Windows 7
MX Linux 19.4 - Windows 7
Re: [Solved] Move scrollbar to show text using code
That's interesting - I don't check previous versions for compatibility, just LibreOffice sometimes.
A more direct way to get the first displayed item would be this (but it uses .getlocation.y too so I presume it won't work in earlier versions either)
Do you need a macro that goes to the next or previous item - its on the scrollbar and the up/down arrow keys for the user already? And you can go to whichever chosen line you want using .makevisible (it could be a heading line perhaps).
If so, I'd suggest a label version reading the lines of a textbox into a label, or a label for each line perhaps, together with a scrollbar control... the scrollbar controls of OO and LO aren't compatible with each other though.
A more direct way to get the first displayed item would be this (but it uses .getlocation.y too so I presume it won't work in earlier versions either)
Code: Select all
case "1","2" 'up,down
lba= lb.accessiblecontext.getaccessiblechild(0).accessiblecontext
cc=lba.getaccessiblechildcount
with lba.getaccessiblechild(0)
i =cint (-.getlocation.y/.getsize.height)
end with
if nm= "2" then
if i <cc-1 then lb.makevisible i+1
else
if i >0 then lb.makevisible i-1
end if
If so, I'd suggest a label version reading the lines of a textbox into a label, or a label for each line perhaps, together with a scrollbar control... the scrollbar controls of OO and LO aren't compatible with each other though.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Solved] Move scrollbar to show text using code
Note that OpenOffice (and I presume LibreOffice) has a very full set of listbox macros under OpenOffice Macros /Tools /Listbox.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: [Solved] Move scrollbar to show text using code
Yet another method of getting the first visible item is this (don't know if will work on earlier versions)
Code: Select all
sub scroll(ev)
dim pt as new com.sun.star.awt.Point
dlg = ev.source.getcontext
lb = dlg.getcontrol("ListBox1")
nm =right(ev.source.model.name,1)
select case nm
case "1","2" 'up,down
cc= lb.itemcount
pt.x= 5
pt.y = 5
ac= lb.accessiblecontext.getaccessiblechild(0).accessiblecontext
j = ac.getaccessibleatpoint(pt)
if isnull(j)=false then
i= j.accessiblecontext.accessibleindexinparent
if nm= "2" then
if i <cc-1 then lb.makevisible i+1
else
if i >0 then lb.makevisible i-1
end if
end if
case "3" 'start
lb.makevisible 0
case "4" 'end
lb.makevisible lb.itemcount -1
end select
end sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Solved] Move scrollbar to show text using code
Thank you RoryOF.RoryOF wrote:Note that OpenOffice (and I presume LibreOffice) has a very full set of listbox macros under OpenOffice Macros /Tools /Listbox.
I din't knew that.
Open Office 4.1.9
MX Linux 19.4 - Windows 7
MX Linux 19.4 - Windows 7
Re: [Solved] Move scrollbar to show text using code
Thank you for your persistance JeJe.
I tried on both portable and installed versions.
Again, doesn't work on earlier editions.
I found that if i scroll the list using the scrollbar, the .getlocation.y gives correct results.
But if i use .makeVisible() to scroll the list, then .getlocation.y gives incorrect results.
Maybe it was a bug on those versions.
I tried on both portable and installed versions.
Again, doesn't work on earlier editions.
I found that if i scroll the list using the scrollbar, the .getlocation.y gives correct results.
But if i use .makeVisible() to scroll the list, then .getlocation.y gives incorrect results.
Maybe it was a bug on those versions.
Open Office 4.1.9
MX Linux 19.4 - Windows 7
MX Linux 19.4 - Windows 7
Re: [Solved] Move scrollbar to show text using code
In that circumstance I look for something that can indirectly reset it to the correct value... redrawing the control or something like (that probably won't work, but something like that, that's otherwise harmless).
(Edit: though of course there may not be anything)
Anyone with the earlier version might be wise to update anyway.
(Edit: though of course there may not be anything)
Anyone with the earlier version might be wise to update anyway.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)