469,951 Members | 2,754 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,951 developers. It's quick & easy.

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

4
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();
}
}
}
Aug 17 '07 #1
0 1072

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Muralidhar | last post: by
14 posts views Thread by Zenobia | last post: by
2 posts views Thread by RWD | last post: by
2 posts views Thread by Mike Brophy | last post: by
6 posts views Thread by C. Moya | last post: by
2 posts views Thread by Benjamin Kalytta | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.