开发者

scrolling two panels at same time c# winForms

yea so I have 2 panels with the same width and the same width of data in them. the top panel has autoscroll enabled. I would like to be able to scroll both panels, with the top panel scrollbar. which means that the bottom panel doesn't have a scroll bar. How would I do that?

alt text http://members.multimania.co.uk/jeff1524/pics/scrolling.jpg

EDIT: I tried panel2.AutoScrollPosition = panel1.AutoScrollPosition; 开发者_StackOverflownothing

I also tried

e.Graphics.DrawRectangle(new Pen(Color.Pink,3), 10, 10, 30, 20);
        e.Graphics.TranslateTransform(panel1.AutoScrollPosition.X, 0);

no movement on the rectangle. What am i doing wrong?


Easy peasy. Implement the Scroll event for the 1st panel and have it Invalidate() the 2nd. Draw the text in the 2nd panel's Paint event, using the scroll position of the 1st:

    private void panel1_Scroll(object sender, ScrollEventArgs e) {
        panel2.Invalidate();
    }

    private void panel2_Paint(object sender, PaintEventArgs e) {
        Point pos = new Point(panel1.AutoScrollPosition.X, 0);
        TextRenderer.DrawText(e.Graphics, "nobugz waz here", panel2.Font, pos, Color.Black);
        // Draw something
        e.Graphics.TranslateTransform(pos.X, pos.Y);
        e.Graphics.DrawLine(Pens.Black, 0, 0, 100, 100);
    }


Even easier.

Just place the panels inside another panel that has the scroll bar (AutoScroll = true). I've used this strategy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜