Questions about ScrollableControl

R

Rune Jacobsen

Hi all,

I have a few questions on deriving from ScrollableControl that I hope
will be relatively easy to answer. I am using Visual Studio 2003, C# and
..Net 1.1.

I have this custom control I am making called ResourceView. It is
supposed to show a visual overview of resource usage over time. Time is
represented by the X axis, and the different resources (people,
equipment, rooms etc.) are in the Y axis. Usually one will view a
limited amount of resources (a logical group/unit for instance) and time
(a 24 hour period) at once, but it will be possible to display all
resources for an entire time period - this will naturally lead to a
large amount of items.

Currently I have one control which is made up of three ScrollableControl
objects (extended slightly to allow me to manually control scroll
positions and also set scroll positions) - on the top is the time ruler,
on the left is the vertical resource list, and the rest (except for the
empty top left corner) is occupied by the actual view. The view is
currently a large canvas where I paint the resource "events" as square
boxes that visually give you an idea how long they last and when they
start in relation to other resource events. Each of these boxes is
actually inside another control (one per resource) that spans the length
of the view and contains all the events of a single resource - I call
these ResourceStrips for now.

When you scroll the view horizontally, the time ruler is also made to
scroll the same amount of pixels, so that the events and their place in
time lines ut properly. Likewise, when the view is scrolled vertically,
the resource list on the left is manually scrolled to keep up.

So far, all is good. I put my ResourceView into a form and dock it to
fill the entire thing. In the controls' OnResize I manually resize the
time (top) and resource (left) controls to keep up - the built in
docking functionality does not work the way I need it to. So the control
resizes beautifully and it all seems relative light on resources.

However, there are a few issues (and finally he gets to the point..?);

1) When I resize the window, the scrollbars on the top and left controls
flash on and off; This seems to happen in the ScrollableControl OnLayout
method, but I am not sure. Can I get rid of this? If I override OnLayout
and don't let it call base.OnLayout(), it stops flashing but it also
stops doing much of anything else, including scrolling.

2) If I click in the main view, it will reset to horizontal position
zero, and scroll vertically so the entire "resource row" (i.e.
ResourceStrip control) is in view. I am guessing this is due to some
sort of EnsureVisible() thing on the ResourceStrip? I think it is worth
nothing that the scroll reset occurs on mousedown - it doesn't wait for
me to release the mouse button. Is this a focus thing? And more
importantly, can I get rid of it?

3) Currently, each resource event (i.e. the square boxes that make up
the contents of the ResourceStrips) is simply painted on - they are not
controls. These controls could get quite heavy, in theory 500-1000
events in one view. I will need these to react to clicks and mouseovers.
Is it better to create these as individual lightweight controls? Or
should I keep painting them as graphics on the ResourceStrips.

I hope some friendly soul can shed some light on this as my head is
almost out of hair..

Thank you very much in advance for the help!

Rune
 
B

Ben Voigt

However, there are a few issues (and finally he gets to the point..?);

1) When I resize the window, the scrollbars on the top and left controls
flash on and off; This seems to happen in the ScrollableControl OnLayout
method, but I am not sure. Can I get rid of this? If I override OnLayout
and don't let it call base.OnLayout(), it stops flashing but it also stops
doing much of anything else, including scrolling.

use SuspendLayout and ResumeLayout when resizing everything.
2) If I click in the main view, it will reset to horizontal position zero,
and scroll vertically so the entire "resource row" (i.e. ResourceStrip
control) is in view. I am guessing this is due to some sort of
EnsureVisible() thing on the ResourceStrip? I think it is worth nothing
that the scroll reset occurs on mousedown - it doesn't wait for me to
release the mouse button. Is this a focus thing? And more importantly, can
I get rid of it?

3) Currently, each resource event (i.e. the square boxes that make up the
contents of the ResourceStrips) is simply painted on - they are not
controls. These controls could get quite heavy, in theory 500-1000 events
in one view. I will need these to react to clicks and mouseovers. Is it
better to create these as individual lightweight controls? Or should I
keep painting them as graphics on the ResourceStrips.

Every control requires an OS window, which won't be as efficient for
hit-testing as a binary search of a sorted list.

Just try and avoid painting areas that are scrolled off-screen, to keep
efficiency up. A resource that is partially visible can be totally painted,
using OS clipping, but if no part of the resource is visible, skip painting
it.

Your culling of off-screen resources will probably be more efficient if you
transform the current visible region back into the units of your x and y
axes (time I guess), instead of computing the screen coordinates for each
resource.
 
R

Rune Jacobsen

Ben said:
use SuspendLayout and ResumeLayout when resizing everything.

Thanks for the suggestion - I was kicking myself that I didn't think of
this myself. However, in the "main" components OnResize() override, I
tried SuspendLayout() on the control itself, and around each of the
other ScrollableControl derived controls when their size was changed,
and when I resize the window now, I still see the scrollbar flashing.

It is perhaps worth noting that in the ScrollableControl's OnLayout
override, I have to call the Win32 function ShowScrollBar and set both
SB_HORZ and SB_VERT to false - otherwise the scrollbar will stay
visible. And I have to do it AFTER I do base.OnLayout(), otherwise the
same will happen again.

So I'm a bit stumped as to what I have to do to keep the control from
wanting to show me the scrollbars - it stops doing it when I set
AutoScroll to false, but then it also doesn't allow me to scroll the
contents anymore..

Someone? Help!? ;)
Every control requires an OS window, which won't be as efficient for
hit-testing as a binary search of a sorted list.

Just try and avoid painting areas that are scrolled off-screen, to keep
efficiency up. A resource that is partially visible can be totally painted,
using OS clipping, but if no part of the resource is visible, skip painting
it.

Your culling of off-screen resources will probably be more efficient if you
transform the current visible region back into the units of your x and y
axes (time I guess), instead of computing the screen coordinates for each
resource.

Great tips, thank you very much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top