System.Windows.Forms.Control.RectangleToClient C# (CSharp) Method

RectangleToClient() public method

public RectangleToClient ( Rectangle r ) : Rectangle
r Rectangle
return Rectangle
		public Rectangle RectangleToClient(Rectangle r) {
			return new Rectangle(PointToClient(r.Location), r.Size);
		}

Usage Example

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
All Usage Examples Of System.Windows.Forms.Control::RectangleToClient
Control