GetChildAtPoint() public method

public GetChildAtPoint ( Point pt ) : Control
pt Point
return Control
 private bool WasNotClickedOnTarget(Control parent, Control target)
 {
     Control clickedOn = parent.GetChildAtPoint(Cursor.Position);
     if (IsNull(clickedOn)) return true;
     if (AreEqual(clickedOn, target)) return false;
     return true;
 }
 private Control FindControl(Control parent, Point p)
 {
     Control c = parent.GetChildAtPoint(p);
     if (c == null) return parent;
     p = new Point(p.X - c.Location.X, p.Y - c.Location.Y);
     return FindControl(c, p);
 }
Beispiel #3
1
 public static Control FindTopControl(Control parent, Point screen_pt)
 {
     Control c = parent.GetChildAtPoint(parent.PointToClient(screen_pt));
     if (c == null) {
         if (parent.RectangleToScreen(new Rectangle(0, 0, parent.Width, parent.Height)).Contains(screen_pt))
             return parent;
         else
             return null;
     }
     else
         return FindTopControl(c, screen_pt);
 }
 private static Control GetVisibleChildAtDesktopPoint( Control topControl, Point desktopPoint )
 {
     Control foundControl = topControl.GetChildAtPoint( topControl.PointToClient( desktopPoint ) );
     if (foundControl != null)
     {
         if (foundControl.HasChildren)
         {
             foreach (Control control in foundControl.Controls)
             {
                 foundControl = GetVisibleChildAtDesktopPoint(control, desktopPoint);
                 if (foundControl != null && foundControl.Visible)
                     break;
             }
         }
     }
     return foundControl ?? topControl;
 }
		public static object CallControlGetChildAtPoint(Control c, object[] obj)
		{
			return c.GetChildAtPoint((Point)obj[0]);
		}
Beispiel #6
0
        //蛇体移动
        public void Move(System.Windows.Forms.Control control)
        {
            if (!this.hasFood)
            {
                control.Controls.Remove(control.GetChildAtPoint(((Label)snake[snake.Count - 1]).Location));
                snake.RemoveAt(snake.Count - 1);
            }
            Label temp = new Label();

            this.CopyBody(temp, (Label)snake[0]);
            switch (this.way)
            {
            case Way.WEST:
            {
                temp.Left -= 10;
                snake.Insert(0, temp);
                break;
            }

            case Way.EAST:
            {
                temp.Left += 10;
                snake.Insert(0, temp);
                break;
            }

            case Way.NORTH:
            {
                temp.Top -= 10;
                snake.Insert(0, temp);
                break;
            }

            case Way.SOUTH:
            {
                temp.Top += 10;
                snake.Insert(0, temp);
                break;
            }
            }
            control.Controls.Add((Label)snake[0]);
            if (this.hasFood)
            {
                this.hasFood = false;
            }
        }
Beispiel #7
0
 public static object CallControlGetChildAtPoint(Control c, object[] obj)
 {
     return(c.GetChildAtPoint((System.Drawing.Point)obj[0]));
 }
Beispiel #8
0
		public void TestPublicMethods ()
		{
			// Public Methods that force Handle creation:
			// - CreateControl ()
			// - CreateGraphics ()
			// - GetChildAtPoint ()
			// - Invoke, BeginInvoke throws InvalidOperationException if Handle has not been created
			// - PointToClient ()
			// - PointToScreen ()
			// - RectangleToClient ()
			// - RectangleToScreen ()
			Control c = new Control ();
			
			c.BringToFront ();
			Assert.IsFalse (c.IsHandleCreated, "A1");
			c.Contains (new Control ());
			Assert.IsFalse (c.IsHandleCreated, "A2");
			c.CreateControl ();
			Assert.IsTrue (c.IsHandleCreated, "A3");
			c = new Control ();
			Graphics g = c.CreateGraphics ();
			g.Dispose ();
			Assert.IsTrue (c.IsHandleCreated, "A4");
			c = new Control ();
			c.Dispose ();
			Assert.IsFalse (c.IsHandleCreated, "A5");
			c = new Control ();
			//DragDropEffects d = c.DoDragDrop ("yo", DragDropEffects.None);
			//Assert.IsFalse (c.IsHandleCreated, "A6");
			//Assert.AreEqual (DragDropEffects.None, d, "A6b");
			//Bitmap b = new Bitmap (100, 100);
			//c.DrawToBitmap (b, new Rectangle (0, 0, 100, 100));
			//Assert.IsFalse (c.IsHandleCreated, "A7");
			//b.Dispose ();
			c.FindForm ();
			Assert.IsFalse (c.IsHandleCreated, "A8");
			c.Focus ();
			Assert.IsFalse (c.IsHandleCreated, "A9");

			c.GetChildAtPoint (new Point (10, 10));
			Assert.IsTrue (c.IsHandleCreated, "A10");
			c.GetContainerControl ();
			c = new Control ();
			Assert.IsFalse (c.IsHandleCreated, "A11");
			c.GetNextControl (new Control (), true);
			Assert.IsFalse (c.IsHandleCreated, "A12");
#if NET_2_0
			c.GetPreferredSize (Size.Empty);
			Assert.IsFalse (c.IsHandleCreated, "A13");
#endif
			c.Hide ();
			Assert.IsFalse (c.IsHandleCreated, "A14");
			c.Invalidate ();
			Assert.IsFalse (c.IsHandleCreated, "A15");
			//c.Invoke (new InvokeDelegate (InvokeMethod));
			//Assert.IsFalse (c.IsHandleCreated, "A16");
			c.PerformLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A17");
			c.PointToClient (new Point (100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A18");
			c = new Control ();
			c.PointToScreen (new Point (100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A19");
			c = new Control ();
			//c.PreProcessControlMessage   ???
			//c.PreProcessMessage          ???
			c.RectangleToClient (new Rectangle (0, 0, 100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A20");
			c = new Control ();
			c.RectangleToScreen (new Rectangle (0, 0, 100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A21");
			c = new Control ();
			c.Refresh ();
			Assert.IsFalse (c.IsHandleCreated, "A22");
			c.ResetBackColor ();
			Assert.IsFalse (c.IsHandleCreated, "A23");
			c.ResetBindings ();
			Assert.IsFalse (c.IsHandleCreated, "A24");
			c.ResetCursor ();
			Assert.IsFalse (c.IsHandleCreated, "A25");
			c.ResetFont ();
			Assert.IsFalse (c.IsHandleCreated, "A26");
			c.ResetForeColor ();
			Assert.IsFalse (c.IsHandleCreated, "A27");
			c.ResetImeMode ();
			Assert.IsFalse (c.IsHandleCreated, "A28");
			c.ResetRightToLeft ();
			Assert.IsFalse (c.IsHandleCreated, "A29");
			c.ResetText ();
			Assert.IsFalse (c.IsHandleCreated, "A30");
			c.SuspendLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A31");
			c.ResumeLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A32");
#if NET_2_0
			c.Scale (new SizeF (1.5f, 1.5f));
			Assert.IsFalse (c.IsHandleCreated, "A33");
#endif
			c.Select ();
			Assert.IsFalse (c.IsHandleCreated, "A34");
			c.SelectNextControl (new Control (), true, true, true, true);
			Assert.IsFalse (c.IsHandleCreated, "A35");
			c.SetBounds (0, 0, 100, 100);
			Assert.IsFalse (c.IsHandleCreated, "A36");
			c.Update ();
			Assert.IsFalse (c.IsHandleCreated, "A37");
		}
Beispiel #9
0
		public void GetChildAtPointTest ()
		{
			Control c = null, d = null;
			TransparentControl e = null;

			try {
				c = new Control ();
				c.Name = "c1";
				c.SetBounds (0, 0, 100, 100);

				d = new Control ();
				d.Name = "d1";
				d.SetBounds (10, 10, 40, 40);
				c.Controls.Add (d);

				e = new TransparentControl ();
				e.Name = "e1";
				e.SetBounds (55, 55, 10, 10);

				Control l = c.GetChildAtPoint (new Point (15, 15));
				Assert.AreEqual (d.Name, l.Name, "Child1");
				Assert.IsFalse (e.Name == l.Name, "Child2");

				l = c.GetChildAtPoint (new Point (57, 57));
				Assert.AreEqual (null, l, "Child3");

				l = c.GetChildAtPoint (new Point (10, 10));
				Assert.AreEqual (d.Name, l.Name, "Child4");

				// GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
#if NET_2_0
				c.Controls.Add (e);
				e.Visible = false;
				l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
				Assert.IsNull (l, "Child5");

				e.Visible = true;
				l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
				Assert.AreSame (e.Name, l.Name, "Child6");

				e.Enabled = false;
				l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
				Assert.IsNull (l, "Child7");

				e.Enabled = true;
				l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
				Assert.AreSame (e.Name, l.Name, "Child8");

				
				e.BackColor = Color.Transparent;
				l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
				Assert.IsNull (l, "Child9");

				e.BackColor = Color.Green;
				l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
				Assert.AreSame (e.Name, l.Name, "Child10");

#endif // NET_2_0
			} finally {
				if (c != null)
					c.Dispose ();
				if (d != null)
					d.Dispose ();
			}
		}