Mediator
Mediator

Reputation: 15378

How make scrollbar in Panel?

I have a Panel, it painted a different Graphics items.

How to scroll without using win api.

Do I get to do if the panel added to Controls, but if you just painted does not work = (

EDIT:

Work, but width and heigth required manul

protected override void OnScroll(ScrollEventArgs se)
{
    base.OnScroll(se);
    if (se.ScrollOrientation == ScrollOrientation.VerticalScroll)
    {
        foreach (Platform platform in m_arPlatforms)
        {
            platform.ReLocation(platform.Location.X, platform.Location.Y + (se.OldValue - se.NewValue));
        }
    }
    if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll)
    {
        foreach (Platform platform in m_arPlatforms)
        {
            platform.ReLocation(platform.Location.X + (se.OldValue - se.NewValue), platform.Location.Y);
        }
    }
}

Upvotes: 0

Views: 2409

Answers (2)

Dan Byström
Dan Byström

Reputation: 9244

I'm not sure I understand your question completely, but provided that you have the AutoScroll working correctly and your problem is that your own painting code is not taking the scrolling into account, then it is as easy as calling .TranslateTransform with the .AutoScrollPosition coordinates.

Upvotes: 0

Davide Piras
Davide Piras

Reputation: 44595

as you can see here: Panel Class, the panel derives from ScrollableControl, just set to true the AutoScroll property and it will work.

Upvotes: 1

Related Questions