/// <summary>
        /// 将控件坐标系的点转换为屏幕坐标系的点
        /// </summary>
        /// <param name="p">点</param>
        /// <returns>转换后的点</returns>
        public Point PointToScreen(Point p)
        {
            IUIControl parent = this;
            IUIWindow  window = null;

            while (parent != null && (window = parent as IUIWindow) == null)
            {
                p.Offset(parent.Left, parent.Top);
                parent = parent.UIParent;
            }
            return(window.PointToScreen(p));
        }
Example #2
0
        public void TestCore(FormBorderStyle border, IUIWindow target)
        {
            //初始化
            this.FormBorderStyle = border;
            this.btnOut.UIParent = target;

            //FindUIWindow
            Assert.AreEqual(btnOut.FindUIWindow(), target);
            Assert.AreEqual(btnInner.FindUIWindow(), target);
            Assert.AreEqual(target.FindUIWindow(), target);

            //FindUIChild
            Assert.AreEqual(target.FindUIChild(Point.Empty), null);
            Assert.AreEqual(target.FindUIChild(new Point(10, 20)), this.btnOut);
            Assert.AreEqual(target.FindUIChild(new Point(109, 69)), this.btnOut);
            Assert.AreEqual(target.FindUIChild(new Point(15, 35)), this.btnInner);
            Assert.AreEqual(target.FindUIChild(new Point(64, 54)), this.btnInner);
            //FindUIChild
            Assert.AreEqual(this.btnOut.FindUIChild(Point.Empty), null);
            Assert.AreEqual(this.btnOut.FindUIChild(new Point(5, 15)), this.btnInner);
            Assert.AreEqual(this.btnOut.FindUIChild(new Point(54, 34)), this.btnInner);
            //FindUIChild
            Assert.AreEqual(target.FindUIChild("in2"), this.btnInner2);
            //PointToClient
            Point p  = new Point(15, 35);//window client
            Point sp = target.PointToScreen(p);

            Assert.AreEqual(target.PointToClient(sp), p);
            Assert.AreEqual(this.btnOut.PointToClient(sp), new Point(5, 15));
            Assert.AreEqual(this.btnInner.PointToClient(sp), Point.Empty);
            //PointToScreen
            Assert.AreEqual(target.PointToScreen(p), sp);
            Assert.AreEqual(this.btnOut.PointToScreen(new Point(5, 15)), sp);
            Assert.AreEqual(this.btnInner.PointToScreen(Point.Empty), sp);
            //PointToUIControl
            Assert.AreEqual(target.PointToUIControl(p), p);
            Assert.AreEqual(this.btnOut.PointToUIControl(p), new Point(5, 15));
            Assert.AreEqual(this.btnInner.PointToUIControl(p), Point.Empty);
            //PointToUIWindow
            Assert.AreEqual(target.PointToUIWindow(p), p);
            Assert.AreEqual(this.btnOut.PointToUIWindow(new Point(5, 15)), p);
            Assert.AreEqual(this.btnInner.PointToUIWindow(Point.Empty), p);
            //RectangleToClient
            Rectangle r  = new Rectangle(15, 35, 10, 20);//window client
            Rectangle sr = target.RectangleToScreen(r);

            Assert.AreEqual(target.RectangleToClient(sr), r);
            Assert.AreEqual(this.btnOut.RectangleToClient(sr), new Rectangle(5, 15, 10, 20));
            Assert.AreEqual(this.btnInner.RectangleToClient(sr), new Rectangle(0, 0, 10, 20));
            //RectangleToScreen
            Assert.AreEqual(target.RectangleToScreen(r), sr);
            Assert.AreEqual(this.btnOut.RectangleToScreen(new Rectangle(5, 15, 10, 20)), sr);
            Assert.AreEqual(this.btnInner.RectangleToScreen(new Rectangle(0, 0, 10, 20)), sr);
            //RectangleToUIControl
            Assert.AreEqual(target.RectangleToUIControl(r), r);
            Assert.AreEqual(this.btnOut.RectangleToUIControl(r), new Rectangle(5, 15, 10, 20));
            Assert.AreEqual(this.btnInner.RectangleToUIControl(r), new Rectangle(0, 0, 10, 20));
            //RectangleToUIWindow
            Assert.AreEqual(target.RectangleToUIWindow(r), r);
            Assert.AreEqual(this.btnOut.RectangleToUIWindow(new Rectangle(5, 15, 10, 20)), r);
            Assert.AreEqual(this.btnInner.RectangleToUIWindow(new Rectangle(0, 0, 10, 20)), r);
            //
            this.btnOut.SendToBack();
            this.btnOut.BringToFront();
        }