Hi,
I have this code working for embedding container controls on a scrolling canvas. However, I only have always used two types of container controls and both were of the same height.
I would like to add the ability to embed another container control object which contains a listbox. This object will be a different height. So, I was wondering if someone could critique my current code to help point me in the right direction of handling embedding container control objects of varying heights.
I realize this isn’t the best code and my comments on how I understand it may not be correct.
Thank you
[code]Sub CCAdd(oContainer As MyScrollViewCC)
// Add the newly created containter to the array of containers
aroContainers.append oContainer
// Check if we need to auto scroll before we embed the new container on the canvas.
//
// If our array of containers contains less containers than the maximium number
// of containers the canvas can display at one time, then set the scroll bar position to 0.
//
// If our array of containers contains more containers than the maximium number
// of containers the canvas can display at one time, then set the scroll bar position down
// to expose the amount of space in pixels needed on the canvas to handle the height of
// one more container.
dim y, offset as integer
container_height = oContainer.height
max_containers = ( self.height \ container_height ) - 1 // maximum # of displayable containers
// y is also where our top container in our list will be. Thats what we want our scrollbar
// to be set to. It points to the top most container.
y = Max( 0, ( aroContainers.Ubound * container_height ) - ( max_containers * container_height ) )
ScrollAutoScrollTo y
if y > 0 then
offset = max_containers * container_height
else
offset = aroContainers.Ubound * container_height
end if
// Add the container to the scroll view canvas
oContainer.embedwithin( self, 0, offset )
oContainer.TabIndex = aroContainers.Ubound
RaiseEvent ScrollViewCCAdded( oContainer )
RaiseEvent ScrollViewChanged
self.Invalidate
End Sub
[/code]
[code]Sub CCRemove(oContainer as MyScrollViewCC)
// Remove the container from the scroll view canvas
Dim i, y, newidx as Integer
RaiseEvent ScrollViewCCRemoved( oContainer )
// Remove specific container from our array of specific containers
i = aroContainers.IndexOf( oContainer )
aroContainers(i).Close
aroContainers.Remove(i)
// Set the new container to adjust our scroll to when we auto scroll
// Set this to one container before the container the user removed.
newidx = Max ( 0, ( i - 1 ) )
// Reposition specific containers
For i = 0 To aroContainers.Ubound
aroContainers(i).Top = i * container_height + self.Top - YScrollLast
aroContainers(i).TabIndex = i
Next
// Check if we need to auto scroll
//
// If our array of containers contains less containers than the maximium number
// of containers the canvas can display at one time, then set the scroll bar position to 0.
//
// If our array of containers contains more containers than the maximium number
// of containers the canvas can display at one time, then set the scroll bar position down
// to expose the amount of space in pixels needed on the canvas to handle the height of
// one more container.
// y is the total pixels our array (up until our newidx element) of containers are over what the canvas can hold in pixels.
// y is also where our top container in our list will be. Thats what we want our scrollbar
// to be set to. It points to the top most container.
y = Max( 0, ( newidx * container_height ) - ( max_containers * container_height ) )
ScrollAutoScrollTo y
RaiseEvent ScrollViewChanged
self.Invalidate
End Sub
[/code]