For a scrollable control the
ClientRectangle
contains just the visible portion of the control. The
DisplayRectangle
is the total area, accessible by scrolling, and the
AutoScrollPosition
gives the offset of the top left corner of the
DisplayRectangle
relative to the
ClientRectangle
.
That's easy to say but probably better understood with a short code fragment which does the required transformation.
private void Panel_MouseClick(object sender, MouseEventArgs e) {
TableLayoutPanel tlp = (TableLayoutPanel)sender;
Point correctedPos = Point.Subtract(e.Location, new Size(tlp.AutoScrollPosition));
Debug.Print("DisplayRectangle{0} ClientRectangle{1} AutoScrollPosition{2}",
tlp.DisplayRectangle, tlp.ClientRectangle, tlp.AutoScrollPosition);
Debug.Print("MouseClick Location{0} Corrected{1}", e.Location, correctedPos);
}
I think that's what you need.
Alan.