I’m using ColumnBrowser made by Amar Sagoo. You can find it here: http://amarsagoo.info/realbasic/index.shtml
I understand that the graphics property of Canvas has been depreciated and that I must use the passed Graphics inside the Paint event.
I’m getting an error on the following line of code inside the scrollbarValueChanged method because of the depreciated Graphics property:
column(actualColumnIndex).draw1( me.graphics, scrollValue, colLeft, colWidth, contentHeight )
What’s the proper way to handle this inside the Paint event? There are other things that happen inside the paint event, but I would only want to execute this code when the scrollbar value changes.
Thanks in advance.
[code]Public Sub scrollbarValueChanged(scrollbar As ColumnBrowserScrollbar)
dim columnIndex, actualColumnIndex, colLeft, colWidth, scrollValue as integer
if scrollbar = horizontalScrollbar then
firstVisibleColumn = max(scrollbar.value, 0)
refresh
else // Vertical Scrollbar
columnIndex = scrollbar.getColumnIndex
actualColumnIndex = columnIndex + firstVisibleColumn
colWidth = getCurrentColumnWidth
if columnIndex = visibleColumnCount-1 then
colWidth = colWidth + (contentWidth mod visibleColumnCount)
end if
if actualColumnIndex <= ubound(columnScrollPosition) then
scrollValue = max(scrollbar.value, 0)
columnScrollPosition(actualColumnIndex) = scrollValue
colLeft = (contentWidth \\ visibleColumnCount) * columnIndex + 1
//me.graphics.drawPicture column(actualColumnIndex).draw(scrollValue, colWidth, contentHeight), colLeft, 1
column(actualColumnIndex).draw1( me.graphics, scrollValue, colLeft, colWidth, contentHeight )
end if
end if
End Sub
[/code]
[code]Public Sub Draw1(g as graphics, yOffset as integer, x as Integer, cellWidth as integer, height as integer)
dim i, firstVisibleCell, lastVisibleCell, pixelsOffFirstCell, currentY as integer
dim center as integer
dim theFont as String
dim theSize as Integer
// Loop through all visible cells:
firstVisibleCell = yOffset \ cellHeight
lastVisibleCell = min(ubound(cell), height\cellHeight + firstVisibleCell + 1)
pixelsOffFirstCell = yOffset mod cellHeight
currentY = - pixelsOffFirstCell
center = cellHeight \ 2
theFont = me.browser.getTextFont
theSize = me.browser.getTextSize
for i = firstVisibleCell to lastVisibleCell
g.textFont = theFont
g.textSize = theSize
if cell(i).IsSelected then
// Draw highlighted background:
g.foreColor = highlightColor
g.fillRect x-1, currentY, cellWidth+1, cellHeight
else
g.foreColor = me.browser.getBackgroundColor
g.fillRect x-1, currentY, cellWidth+1, cellHeight
end if
// Draw caption:
g.foreColor = textColor
g.drawString cell(i).getCaption, x, currentY + center + g.textHeight/4 + 2
// Draw icon:
//g.drawPicture cell(i).getIcon, x + (cellWidth-10), currentY + (center - 7)
if cell(i).isBranchNode() then
Dim points(6) As Integer
points(1) = x + (cellWidth - 10)
points(2) = currentY + 5
points(3) = x + cellWidth - 3
points(4) = currentY+center
points(5) = x + (cellWidth - 10)
points(6) = currentY + cellHeight - 5
g.ForeColor = rgb(139,139,139)
g.FillPolygon(points)
end if
currentY = currentY + cellHeight
next
End Sub
[/code]
[code]Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
dim i as integer
dim colLeft, colWidth, colNum as integer
if width <> lastWidth or height <> lastHeight or left <> lastLeft or top <> lastTop then
// Resized:
calculateVisibleColumnCount
arrangeScrollbars
end if
// Store current values:
lastLeft = left
lastTop = top
lastWidth = width
lastHeight = height
// Draw Frame:
'g.foreColor = frameColor
'g.drawRect 0, 0, width, height
// Draw Columns:
g.foreColor = getBackgroundColor
// MS Add (
// Draw Background:
g.fillRect 0, 0, width, height
// )
for i = 0 to visibleColumnCount-1
colLeft = (contentWidth \ visibleColumnCount) * i + 1
colWidth = getCurrentColumnWidth
if i = visibleColumnCount-1 then
colWidth = colWidth + (contentWidth mod visibleColumnCount)
end if
// MS Remove (
// Draw Background:
//g.fillRect colLeft, 1, colWidth, contentHeight
// )
colNum = i + firstVisibleColumn
if colNum <= ubound(column) then
// Setup scrollbar for column:
verticalScrollbar(i).setValueAndMaxWithoutUpdate(columnScrollPosition(colNum), column(colNum).getTotalHeight - contentHeight)
verticalScrollbar(i).lineStep = column(colNum).getCellHeight
columnScrollPosition(colNum) = max(verticalScrollbar(i).value, 0)
// Draw its contents:
// MS Remove (
//g.drawPicture column(colNum).draw(getColumnScrollPosition(colNum), colWidth, contentHeight), colLeft, 1
// )
// MS Add (
column(colNum).draw1( g, getColumnScrollPosition(colNum), colLeft, colWidth, contentHeight )
// )
else
verticalScrollbar(i).setValueAndMaxWithoutUpdate(0,0)
end if
next
End Sub
[/code]