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 = GetPageNumberAtPoint(new Point(Width / 2, scrollValue));
if (activePage > -1)
{
//Calculating the location of the page
Rectangle firstRect = _currentRectPages[activePage];
Point firstPageLoc = new Point(5);
Point secondPageLoc = new Point(5);
if (firstRect.Width < Width)
firstPageLoc = new Point(Width / 2 - firstRect.Width / 2);
Point p = new Point(firstPageLoc.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 < _defaultRectPages.Length & _pnlPages[activePage].Location.Y < 0)
{
Rectangle secondRect = _currentRectPages[activePage + 1];
if (secondRect.Width < Width)
secondPageLoc = new Point(Width / 2 - secondRect.Width / 2);
_pnlPages[activePage + 1].Location = new Point(secondPageLoc.X - hScroll.Value,
(firstRect.Top - vScroll.Value) + firstRect.Height + 5);
_pnlPages[activePage + 1].Visible = true;
_pnlPages[activePage].Invalidate();
}
}
}