Is there a way to change the position of the child control on scrolling

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Assam
    New Member
    • Aug 2007
    • 4

    Is there a way to change the position of the child control on scrolling

    I am developing a custom control which would act as a PDF viewer. I am extending this control from the Panel control(Please note i have enabled double buffering of controls). I am not using the auto scroll property i.e. i am manually controlling the scrolling. The control works fine if there are no controls. But when there are controls in it then i have to change the poistion of the controls when the scroll bar value changes. The problem is there's alot of flickering of child controls. Please see the code below may be i am doing something wrong. Also please note that i have to dynamically judge the position of the child controls

    private void RenderPDFFields ()
    {
    int scrollValue = vScroll.Value == 0 ? 10 : vScroll.Value;
    //Getting the current PDF page
    int activePage = GetPageNumberAt Point(new Point(Width / 2, scrollValue));

    if (activePage > -1)
    {
    //Calculating the location of the page
    Rectangle firstRect = _currentRectPag es[activePage];
    Point firstPageLoc = new Point(5);
    Point secondPageLoc = new Point(5);

    if (firstRect.Widt h < Width)
    firstPageLoc = new Point(Width / 2 - firstRect.Width / 2);

    Point p = new Point(firstPage Loc.X - hScroll.Value,
    firstRect.Top - vScroll.Value);
    _pnlPages[activePage].Location = p;

    _pnlPages[activePage].Visible = true;
    _pnlPages[activePage].Invalidate();

    //Hiding previous page
    if (activePage > 0)
    _pnlPages[activePage - 1].Visible = false;

    //If there's enough virtual space left then show the next page as well
    if (activePage + 1 < _defaultRectPag es.Length & _pnlPages[activePage].Location.Y < 0)
    {
    Rectangle secondRect = _currentRectPag es[activePage + 1];
    if (secondRect.Wid th < Width)
    secondPageLoc = new Point(Width / 2 - secondRect.Widt h / 2);

    _pnlPages[activePage + 1].Location = new Point(secondPag eLoc.X - hScroll.Value,
    (firstRect.Top - vScroll.Value) + firstRect.Heigh t + 5);

    _pnlPages[activePage + 1].Visible = true;
    _pnlPages[activePage].Invalidate();
    }
    }
    }
Working...