views:

479

answers:

1

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

EDIT: I tried panel2.AutoScrollPosition = panel1.AutoScrollPosition; nothing

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?

+3  A: 

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);
    }
Hans Passant
thx nobugz :)))
jello
hmmmm would you know of another technique, because I won't be storing just a label in the second panel. I'd like to store graphics or something
jello
Drawn graphics can be offset the same way, use e.Graphics.TranslateTransform(). And you can set panel2's AutoScrollPosition. Lots of choices.
Hans Passant
hmmm I tried finding documentation on e.Graphics.TransateTransform(), but didn't really understand what it is, or see the relation with what I'm trying to do.
jello
Hmm, you are humming a lot. I updated my post with the required code.
Hans Passant
hmmmmmm thx a lot nobugz :)
jello