Пример #1
0
        public static void WindowlessBringIntoView(IWindowlessControl control)
        {
            WindowlessControlHost host = GetHost(control);

            host.SyncWindows();
            Point     p    = WindowlessPointToHost(control, Point.Empty);
            Rectangle rect = new Rectangle(p.X, p.Y, control.Width, control.Height);

            while (host != null)
            {
                if (host.AutoScroll)
                {
                    Point newScroll = host.AutoScrollPosition;
                    // we favor top and left over bottom and right
                    if (rect.Top < 0)
                    {
                        newScroll.Y -= rect.Top;
                    }
                    else if (rect.Bottom > host.Height && rect.Height <= host.Height)
                    {
                        newScroll.Y += (host.Height - rect.Bottom);
                    }
                    if (rect.Left < 0)
                    {
                        newScroll.X -= rect.Left;
                    }
                    else if (rect.Right > host.Width && rect.Width <= host.Width)
                    {
                        newScroll.Y += (host.Width - rect.Right);
                    }
                    // for some reason you need to pass in positive values to autoscroll, and it converts them to negative values...
                    if (newScroll != host.AutoScrollPosition)
                    {
                        host.AutoScrollPosition = new Point(Math.Abs(newScroll.X), Math.Abs(newScroll.Y));
                        host.SyncWindows();
                    }
                }

                rect.X += host.Left;
                rect.Y += host.Top;
                host    = host.Parent as WindowlessControlHost;
            }
        }