logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
matt.smokeball  
#1 Posted : Thursday, June 28, 2018 8:36:31 PM(UTC)
Quote
matt.smokeball

Rank: Member

Groups: Registered
Joined: 4/15/2018(UTC)
Posts: 24
Man
Australia
Location: Sydney

Thanks: 2 times
Hi

Great product, I'm loving using it and how customizable it can be!

I'm trying to determine if the first control on a field is currently visible in the viewer. I'm using the current code in an extended PdfViewer (WPF) class.

There's definitely something wrong with it. Was hoping you could please point me in the right direction. I think what I have is completely wrong, even though it works sometimes.

Thanks for your help

Code:


private Rect GetControlDimensions(PdfControl ctrl, int pageIndex)
{
    Point pt1 = PageToClient(pageIndex, new Point(ctrl.BoundRect.left, ctrl.BoundRect.top));
    Point pt2 = PageToClient(pageIndex, new Point(ctrl.BoundRect.right, ctrl.BoundRect.bottom));

    //The page may be rotated, so we must take it into account
    int left = (int)Math.Min(pt1.X, pt2.X);
    int top = (int)Math.Min(pt1.Y, pt2.Y);
    int right = (int)Math.Max(pt1.X, pt2.X);
    int bottom = (int)Math.Max(pt1.Y, pt2.Y);

    return new Rect(left, top, right - left, bottom - top);
}

private bool IsFieldVisible(PdfField field)
{
   PdfControl ctrl = field.Controls.FirstOrDefault();

    if (ctrl != null)
    {
        Rect dimensions = GetControlDimensions(ctrl, CurrentIndex);

        if (dimensions.Top > 0 && dimensions.Bottom < ViewportHeight)
        {
            return true;
        }
    }

    return false;
}

Paul Rayman  
#2 Posted : Friday, June 29, 2018 4:53:09 AM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
What's wrong with this code? It works great for me.
The only one thing to consider is that the controls of the field can be placed on a several pages.
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.