Well, I can’t because this is part of a larger component, called ColumnBrowser made by Amar Sagoo. You can find it here: http://amarsagoo.info/realbasic/index.shtml
Take a look at the Open() event of the ColumnBrowser canvas:
[code] dim i, controlCount, scrollersNeeded as integer
dim scroller as ColumnBrowserScrollbar
setMinColumnWidth(160)
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
else
// Make it a vertical scrollbar:
verticalScrollbar.append scroller
end if
scrollersNeeded = scrollersNeeded - 1
if scrollersNeeded <= 0 then
// Enough scrollbars found:
exit
end if
end if
end if
next
// Check if enough scrollbars were found:
if scrollersNeeded > 0 then
msgBox “Not enough scrollbars available for column browser!”
quit
return
end if
arrangeScrollbars
// Let user do further initialisation:
Open()
[/code]
[code]Protected Sub arrangeScrollbars()
dim i, colWidth, colNum as integer
// Setup horizontal scrollbar:
horizontalScrollbar.left = me.left + 1
horizontalScrollbar.top = me.top + me.height - 16
horizontalScrollbar.width = me.width - 17
horizontalScrollbar.height = 16
horizontalScrollbar.visible = me.visible
horizontalScrollbar.enabled = true
horizontalScrollbar.updateMaxAndPageStep(me)
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
else
verticalScrollbar(i).left = me.left + colWidth * (i+1) - 14
end if
verticalScrollbar(i).top = me.top + 1
verticalScrollbar(i).width = 16
verticalScrollbar(i).height = me.contentHeight+1
verticalScrollbar(i).pageStep = me.contentHeight
verticalScrollbar(i).visible = true
else
verticalScrollbar(i).visible = false
end if
next
End Sub
[/code]