/// <summary>
        /// Coordinates from control on toplevel control or desktop
        /// </summary>
        /// <param name="control">target control</param>
        /// <returns>coordinates</returns>
        public static Rectangle Coordinates(this Control control)
        {
            Rectangle coordinates;
            Form      form = control.TopLevelControl as Form;

            if (control == form)
            {
                coordinates = form.ClientRectangle;
            }
            else
            {
                coordinates = form.RectangleToClient(control.Parent.RectangleToScreen(control.Bounds));
            }

            return(coordinates);
        }
Exemple #2
0
        public static Rectangle Coordinates(this Control control)
        {
            // Extend System.Windows.Forms.Control to have a Coordinates property.
            // The Coordinates property contains the control's form-relative location.
            Rectangle coordinates;
            Form      form = (Form)control.TopLevelControl;

            if (control == form)
            {
                coordinates = form.ClientRectangle;
            }
            else
            {
                coordinates = form.RectangleToClient(control.Parent.RectangleToScreen(control.Bounds));
            }

            return(coordinates);
        }
Exemple #3
0
            /// <summary>
            /// Captures the specified area of the control or whats underneath
            /// </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 void Control(System.Windows.Forms.Form ctl)
            {
                Bitmap    bmp;                                                                  // capture bitmap
                Rectangle ctlR;                                                                 // capture area rectangle in control coordinates
                Rectangle scrR;                                                                 // capture area rectangle in screen coordinates
                int       m_hDelay = 0;

                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

                ctl.Opacity = 0;
                System.Threading.Thread.Sleep(m_hDelay);

                Single oprvV = (float)ctl.Opacity;                                      // save control visibility

                if (oprvV > 0)                                                          // if control visible
                {
                    ctl.Opacity = 0;
                    ctl.Refresh();
                }

                IntPtr desktopHWND = USER32.GetDesktopWindow(); // get window handle for desktop

                bmp = Window(desktopHWND, scrR);                // get bitmap for capture area under control
                if (ctl.Opacity < 1)
                {
                    ctl.BackgroundImage = bmp;
                    ctl.Refresh();
                    System.Threading.Thread.Sleep(m_hDelay);
                    ctl.Opacity = 1;
                }
                System.GC.Collect();
            }
Exemple #4
0
        public virtual void DrawTrackerRect(Rectangle Rect, Form ClipToFrm,Graphics gs,Control frm)
        {
            Rectangle rect = Rect;
            // convert to client coordinates
            if (ClipToFrm != null)
            {
                rect=ClipToFrm.RectangleToScreen(rect);
                rect=ClipToFrm.RectangleToClient(rect);
            }

            Size size=new Size(0, 0);
            if (!m_bFinalErase)
            {
                // otherwise, size depends on the style
                if ((m_nStyle & StyleFlags.hatchedBorder)!=0)
                {
                    size.Width = size.Height = Math.Max(1, GetHandleSize(rect)-1);
                    rect.Inflate(size);
                }
                else
                {
                    size.Width = CX_BORDER;
                    size.Height = CY_BORDER;
                }
            }

            if (m_bFinalErase || !m_bErase)
            {
                Rectangle rcScreen = frm.RectangleToScreen(rect);
                Rectangle rcLast = frm.RectangleToScreen(m_rectLast);
                DrawDragRect(gs,rcScreen,rcLast);
            }
            // remember last rectangles
            m_rectLast = rect;
            m_sizeLast = size;
        }
Exemple #5
0
		public void TestPublicMethods ()
		{
			// Public Methods that force Handle creation:
			// - CreateGraphics ()
			// - GetChildAtPoint ()
			// - Invoke, BeginInvoke throws InvalidOperationException if Handle has not been created
			// - PointToClient ()
			// - PointToScreen ()
			// - RectangleToClient ()
			// - RectangleToScreen ()
			// - Select ()
			// - Show (IWin32Window)
			// Notes:
			// - CreateControl does NOT force Handle creation!
			
			Form c = new Form ();

			c.BringToFront ();
			Assert.IsFalse (c.IsHandleCreated, "A1");
			
			c.Contains (new Form ());
			Assert.IsFalse (c.IsHandleCreated, "A2");
			
			c.CreateControl ();
			Assert.IsFalse (c.IsHandleCreated, "A3");
			
			c = new Form ();
			Graphics g = c.CreateGraphics ();
			g.Dispose ();
			Assert.IsTrue (c.IsHandleCreated, "A4");
			c.Dispose ();
			c = new Form ();
			
			c.Dispose ();
			Assert.IsFalse (c.IsHandleCreated, "A5");
			c = new Form ();

			// This is weird, it causes a form to appear that won't go away until you move the mouse over it, 
			// but it doesn't create a handle??
			//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.Dispose ();
			c = new Form ();
			
			c.GetContainerControl ();
			Assert.IsFalse (c.IsHandleCreated, "A11");
			c.Dispose ();
			
			c = new Form ();
			c.GetNextControl (new Control (), true);
			Assert.IsFalse (c.IsHandleCreated, "A12");
			c.GetPreferredSize (Size.Empty);
			Assert.IsFalse (c.IsHandleCreated, "A13");
			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.Dispose ();
			c = new Form ();
			
			c.PointToScreen (new Point (100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A19");
			c.Dispose ();
			
			c = new Form ();
			
			//c.PreProcessControlMessage   ???
			//c.PreProcessMessage          ???
			c.RectangleToClient (new Rectangle (0, 0, 100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A20");
			c.Dispose ();
			c = new Form ();
			c.RectangleToScreen (new Rectangle (0, 0, 100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A21");
			c.Dispose ();
			c = new Form ();
			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");
			c.Scale (new SizeF (1.5f, 1.5f));
			Assert.IsFalse (c.IsHandleCreated, "A33");
			c.Select ();
			Assert.IsTrue (c.IsHandleCreated, "A34");
			c.Dispose ();
			
			c = new Form ();
			
			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");
			
			// Form
			
			c.Activate ();
			Assert.IsFalse (c.IsHandleCreated, "F1");
			
			c.AddOwnedForm (new Form ());
			Assert.IsFalse (c.IsHandleCreated, "F2");
			
			c.Close ();
			Assert.IsFalse (c.IsHandleCreated, "F3");
			
			c.Hide ();
			Assert.IsFalse (c.IsHandleCreated, "F4");
			
			c.LayoutMdi (MdiLayout.Cascade);
			Assert.IsFalse (c.IsHandleCreated, "F5");

#if !MONO
			c.PerformAutoScale ();
			Assert.IsFalse (c.IsHandleCreated, "F6"); 
#endif
			
			c.PerformLayout ();
			Assert.IsFalse (c.IsHandleCreated, "F7");
			
			c.AddOwnedForm (new Form ());
			c.RemoveOwnedForm (c.OwnedForms [c.OwnedForms.Length - 1]);
			Assert.IsFalse (c.IsHandleCreated, "F8");
			
			c.ScrollControlIntoView (null);
			Assert.IsFalse (c.IsHandleCreated, "F9");
			
			c.SetAutoScrollMargin (7, 13);
			Assert.IsFalse (c.IsHandleCreated, "F10");
			
			c.SetDesktopBounds (-1, -1, 144, 169);
			Assert.IsFalse (c.IsHandleCreated, "F11");
			
			c.SetDesktopLocation (7, 13);
			Assert.IsFalse (c.IsHandleCreated, "F12");

			c = new Form ();
			c.Show (null);
			Assert.IsTrue (c.IsHandleCreated, "F13");
			c.Close ();
			c = new Form (); 
			
			//c.ShowDialog ()
			
			c.ToString ();
			Assert.IsFalse (c.IsHandleCreated, "F14");
			
			c.Validate ();
			Assert.IsFalse (c.IsHandleCreated, "F15");

#if !MONO
			c.ValidateChildren ();
			Assert.IsFalse (c.IsHandleCreated, "F16"); 
#endif

			c.Close ();
		}