Scrollbars on Custom Control

G

gotcode

Hello,
I'm seeing some weird behavior and the MSDN documentation is lacking in
an example of actual usage.
What I've done is create a custom control that derives from either
ScrollableControl. I want a vertical ScrollBar that I can control the
visibility and parameters of. To accomplish this I have:
-set AutoScroll to false (I want to manage the visibility)
-set VerticalScroll.xxxxx properties to the values I want (Min=0,
Max=100, Visible=true, Enabled=true)
-set up a handler for the Scroll event.

The odd thing is that the scroll handler works and I get the event and
the ScrollEventArgs.NewValue looks good when I use the scrollbar, but
no amount of scrolling or setting VerticalScroll.Value actually changes
the value. The value always gets reset to 0 before my paint is called.
I overrode the WndProc and there are two WM_VSCROLL messages being
sent - one for the page down, and the other for the end scroll. That
all looks good. I stepped through some IL and it looks like the
SB_ENDSCROLL message is calling SyncScrollBars which sets the vertical
scroll bar's value back to 0 for some reason.

I also noticed some oddness around the VerticalScroll and VScroll
properties. Setting VScroll to true causes VerticalScroll.Visible to
be set to false and VerticalScroll.Value to be set to 0. Also, setting
VerticalScroll.Value to anything, or setting VerticalScroll.Visible to
true causes VScroll to be set to false.

All of the examples I can find are using AutoScroll = true and I don't
want AutoScroll managing my scrollbars for me.

Thanks for any help

-cryptyk
 
G

gotcode

Hello,
I'm seeing some weird behavior and the MSDN documentation is lacking in
an example of actual usage.
What I've done is create a custom control that derives from either
ScrollableControl. I want a vertical ScrollBar that I can control the
visibility and parameters of. To accomplish this I have:
-set AutoScroll to false (I want to manage the visibility)
-set VerticalScroll.xxxxx properties to the values I want (Min=0,
Max=100, Visible=true, Enabled=true)
-set up a handler for the Scroll event.

The odd thing is that the scroll handler works and I get the event and
the ScrollEventArgs.NewValue looks good when I use the scrollbar, but
no amount of scrolling or setting VerticalScroll.Value actually changes
the value. The value always gets reset to 0 before my paint is called.
I overrode the WndProc and there are two WM_VSCROLL messages being
sent - one for the page down, and the other for the end scroll. That
all looks good. I stepped through some IL and it looks like the
SB_ENDSCROLL message is calling SyncScrollBars which sets the vertical
scroll bar's value back to 0 for some reason.

I also noticed some oddness around the VerticalScroll and VScroll
properties. Setting VScroll to true causes VerticalScroll.Visible to
be set to false and VerticalScroll.Value to be set to 0. Also, setting
VerticalScroll.Value to anything, or setting VerticalScroll.Visible to
true causes VScroll to be set to false.

All of the examples I can find are using AutoScroll = true and I don't
want AutoScroll managing my scrollbars for me.

Thanks for any help

-cryptyk


So right now I've added my own VScrollBar control as a child to my
custom control, and I handle everything related to scrolling myself.
This works, but I'm still interested in how the ScrollableControl/Panel
scrollbars are supposed to work.

Thanks
-cryptyk
 

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