RectangleToClient() public method

public RectangleToClient ( Rectangle r ) : Rectangle
r Rectangle
return Rectangle
Example #1
0
        }                                                                       // end method Control

        /// <summary>
        /// Captures the specified area of the control or whats underneath
        /// the control. If the argument flag client is true, only the client
        /// area of the control is captured, otherwise the entire control is
        /// captured. If the argument flag under is true, the capture area under
        /// the control is captured, otherwise the specified area on the control
        /// is captured.
        /// </summary>
        /// <param name="ctl">Control to capture</param>
        /// <param name="client">If true capture only client area else entire control.</param>
        /// <param name="under">If true capture specified area underneath the control else whats on the control.</param>
        /// <returns>bitmap image of the control or whats underneath the control</returns>
        public static Bitmap    Control(System.Windows.Forms.Control ctl, bool client, bool under)
        {
            Bitmap    bmp;                                                                      // capture bitmap
            Rectangle ctlR;                                                                     // capture area rectangle in control coordinates
            Rectangle scrR;                                                                     // capture area rectangle in screen coordinates

            //	get capture rectangle in control
            //	coordinates and in screen coordinates
            if (client)                                                         // if capturing client area
            {
                ctlR = ctl.ClientRectangle;                                     //   get rectangle in control coordinates
                scrR = ctl.RectangleToScreen(ctlR);                             //   get rectangle in screen coordinates
            }
            else                                                                // if capturing entire control
            {
                scrR = ctl.Bounds;                                              //   get rectangle in parent coordinates
                if (ctl.Parent != null)                                         //   if parent exists
                {
                    scrR = ctl.Parent.RectangleToScreen(scrR);                  //     map to screen coordinates
                }
                ctlR = ctl.RectangleToClient(scrR);                             //   get rectangle in control coordinates
            }

            //	capture an area under the control
            if (under)                                                                  // if capture area is under control
            {
                bool prvV = ctl.Visible;                                                //   save control visibility
                if (prvV)                                                               //   if control visible
                {
                    ctl.Visible = false;                                                //     make control invisible
                    Thread.Sleep(m_HDelay);                                             //     allow time for control to become invisible
                    //     prior to image capture
                }

                //	Capture the bitmap using desktop window handle and screen coordinates
                //	for the capture area. Note, the control window handle can NOT be used
                //  for capturing an area under the control.
                IntPtr desktopHWND = USER32.GetDesktopWindow();                         // get window handle for desktop
                bmp = Window(desktopHWND, scrR);                                        // get bitmap for capture area under control
                if (ctl.Visible != prvV)                                                //   if control visibility was changed
                {
                    ctl.Visible = prvV;                                                 //     restore previous visibility
                }
            }

            //	capture an area on the control
            else                                                                                        // if capture area not under control
            {
                //	Capture the bitmap using control window handle and control coordinates
                //	for capture area.
                bmp = Window(ctl.Handle, ctlR);                                 //   get bitmap using control window handle
            }
            return(bmp);                                                        // return requested bitmap
        }                                                                       // end method Control
Example #2
0
 public static Rectangle getVisibleRectangle(Control panel, Control insideControl)
 {
     Rectangle rect = panel.RectangleToScreen(panel.ClientRectangle);
     while (panel != null)
     {
         rect = Rectangle.Intersect(rect, panel.RectangleToScreen(panel.ClientRectangle));
         panel = panel.Parent;
     }
     rect = insideControl.RectangleToClient(rect);
     return rect;
 }
Example #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            // 禁用重绘事件,仅在设计器模式下启用
            if (DesignMode || UseOwnPaint)
            {
                base.OnPaint(e);
                Graphics g = e.Graphics;
                g.Clear(this.BackColor);

                if (Parent != null && this.BackColor == Color.Transparent)
                {
                    //g.Clear(Parent.BackColor);
                    // 找到有背景图像的上级控件
                    Control parentThatOwnsBgImage = Parent;
                    Image   bgImage = Parent.BackgroundImage;
                    if (parentThatOwnsBgImage.BackgroundImage == null && parentThatOwnsBgImage.BackColor == Color.Transparent)
                    {
                        while (parentThatOwnsBgImage != null)
                        {
                            parentThatOwnsBgImage = parentThatOwnsBgImage.Parent;
                            if (parentThatOwnsBgImage != null &&
                                parentThatOwnsBgImage.BackgroundImage != null)
                            {
                                bgImage = parentThatOwnsBgImage.BackgroundImage;
                                break;
                            }
                        }
                    }


                    if (bgImage != null)
                    {
                        // 算控件在上级控件(有背景图像的上级容器)中的位置,算得不对,需要修改
                        Rectangle boundsInParent = parentThatOwnsBgImage.RectangleToClient(this.ActualBounds);
                        g.DrawImage(bgImage, this.ClientRectangle, boundsInParent.X, boundsInParent.Y, this.Width, this.Height, GraphicsUnit.Pixel);
                    }
                }

                if (this.BackgroundImage != null)
                {
                    g.DrawImage(this.BackgroundImage, 0, 0);
                }

                if (this.NormalImage != null)
                {
                    g.DrawImage(this.NormalImage, this.ClientRectangle);
                }
            }
        }
		public static object CallControlRectangleToClient(Control c, object[] obj)
		{
			return c.RectangleToClient((Rectangle)obj[0]);
		}
Example #5
0
 public static object CallControlRectangleToClient(Control c, object[] obj)
 {
     return(c.RectangleToClient((System.Drawing.Rectangle)obj[0]));
 }
Example #6
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");
		}
Example #7
0
 /// <summary>
 /// Refreshes the drawn rectangle.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="endPoint">The end point.</param>
 private void RefreshDrawnRectangle(Control control, Point endPoint)
 {
     var screenRectangle = new Rectangle(
                         Math.Min(this.startPoint.X, endPoint.X),
                         Math.Min(this.startPoint.Y, endPoint.Y),
                         Math.Abs(this.selectionRectangle.Width),
                         Math.Abs(this.selectionRectangle.Height));
     this.drawnRectangle = control.RectangleToClient(screenRectangle);
 }