Setup A Horizontal Scrollbar Programmatically Not Working

This code used to work in Real Studio.

For simplicity, I created a new project with one scrollbar (Scrollbar1) and one canvas (Canvas1) placed on the window.

The scrollbar was placed on the window in vertical orientation.

The canvas dimensions are:
Width: 400 Height: 200

The scrollbar dimensions are:
Width: 15 Height: 200

In the Open() event of the window I have this:

ScrollBar1.left = Canvas1.left + 1 = + Canvas1.height - 2 ScrollBar1.width = Canvas1.width - 2 ScrollBar1.height = 16 ScrollBar1.visible = true ScrollBar1.enabled = true

The change from vertical scrollbar to horizontal scrollbar never happens.

Thank you

If it won’t switch orientations at runtimes it might be related to the framework. Why not just put the scrollbar on the window in horizontal orientation, or have two scrollbars if you need to switch between horizontal/vertical, and show/hide as needed?

Well, I can’t because this is part of a larger component, called ColumnBrowser made by Amar Sagoo. You can find it here:

Take a look at the Open() event of the ColumnBrowser canvas:

[code] dim i, controlCount, scrollersNeeded as integer
dim scroller as ColumnBrowserScrollbar

setBackgroundColor fillColor
setTextFont “System”
setTextSize 12

maxColumnCount = getMaxColumnCount()
if maxColumnCount < 1 then
maxColumnCount = 3
end if
scrollersNeeded = maxColumnCount+1

// Find scrollbars:
controlCount = me.window.controlCount
for i = 0 to controlCount
if me.window.control(i) isA ColumnBrowserScrollbar then
// Scrollbar found.
scroller = ColumnBrowserScrollbar (me.window.control(i))
if scroller.register(me, ubound(verticalScrollbar)+1) then
// Scrollbar not used yet.
if horizontalScrollbar = nil then
// Make it the horizontal scrollbar:
horizontalScrollbar = scroller
// Make it a vertical scrollbar:
verticalScrollbar.append scroller
end if

    scrollersNeeded = scrollersNeeded - 1
    if scrollersNeeded <= 0 then
      // Enough scrollbars found:
    end if
  end if
end if


// Check if enough scrollbars were found:
if scrollersNeeded > 0 then
msgBox “Not enough scrollbars available for column browser!”
end if


// Let user do further initialisation:

[code]Protected Sub arrangeScrollbars()
dim i, colWidth, colNum as integer

// Setup horizontal scrollbar:
horizontalScrollbar.left = me.left + 1 = + me.height - 16
horizontalScrollbar.width = me.width - 17
horizontalScrollbar.height = 16
horizontalScrollbar.visible = me.visible
horizontalScrollbar.enabled = true
firstVisibleColumn = max(horizontalScrollbar.value, 0)

// Setup vertical scrollbars:

colWidth = contentWidth \ visibleColumnCount

for i = 0 to maxColumnCount-1
if i < visibleColumnCount then
if i = visibleColumnCount-1 then
verticalScrollbar(i).left = me.left + me.width - 16
verticalScrollbar(i).left = me.left + colWidth * (i+1) - 14
end if
verticalScrollbar(i).top = + 1
verticalScrollbar(i).width = 16
verticalScrollbar(i).height = me.contentHeight+1
verticalScrollbar(i).pageStep = me.contentHeight
verticalScrollbar(i).visible = true

  verticalScrollbar(i).visible = false
end if

End Sub

Just to close up this thread, I had to change one of the scrollbars of the control set to be in horizontal orientation, as Tom said.

Then I changed line 24 of the Open event to:

        if horizontalScrollbar = nil and (scroller.width > scroller.height) then