Ejemplo n.º 1
0
        public static Point[] Draw(Pen pen, Form parent)
        {
            sPen = pen;
            // Record the start point
            mPos = parent.PointToClient(Control.MousePosition);
            // Create a transparent form on top of  the parent form
            mMask = new Form();
            mMask.FormBorderStyle = FormBorderStyle.None;
            mMask.BackColor = Color.Magenta;
            mMask.TransparencyKey = mMask.BackColor;

            mMask.ShowInTaskbar = false;
            mMask.StartPosition = FormStartPosition.Manual;
            mMask.Size = parent.ClientSize;
            mMask.Location = parent.PointToScreen(Point.Empty);
            mMask.MouseMove += MouseMove;
            mMask.MouseUp += MouseUp;
            mMask.Paint += PaintRectangle;
            mMask.Load += DoCapture;
            // Display the overlay
            mMask.ShowDialog(parent);
            // Clean-up and calculate return value
            mMask.Dispose();
            mMask = null;
            var pos = parent.PointToClient(Control.MousePosition);

            return new[] {mPos, pos};
        }
 public static Control FindControlAtCursor(Form form)
 {
     Point pos = Cursor.Position;
     if (form.Bounds.Contains(pos))
         return FindControlAtPoint(form, form.PointToClient(Cursor.Position));
     return null;
 }
Ejemplo n.º 3
0
        public Input(Form form)
        {
            this.form = form;

            KeysDown = new List<Keys>();
            KeysPressed = new List<Keys>();
            KeysReleased = new List<Keys>();
            MousePoint = form.PointToClient(Cursor.Position);
            MouseWheelDelta = 0;
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Returns a quaternion for the rotation implied by the window's cursor position
    /// </summary>
    public static Quaternion GetRotationFromCursor(System.Windows.Forms.Form control, float fTrackBallRadius)
    {
        System.Drawing.Point     pt = System.Windows.Forms.Cursor.Position;
        System.Drawing.Rectangle rc = control.ClientRectangle;
        pt = control.PointToClient(pt);
        float xpos = (((2.0f * pt.X) / (rc.Right - rc.Left)) - 1);
        float ypos = (((2.0f * pt.Y) / (rc.Bottom - rc.Top)) - 1);
        float sz;

        if (xpos == 0.0f && ypos == 0.0f)
        {
            return(new Quaternion(0.0f, 0.0f, 0.0f, 1.0f));
        }

        float d2 = (float)Math.Sqrt(xpos * xpos + ypos * ypos);

        if (d2 < fTrackBallRadius * 0.70710678118654752440)         // Inside sphere
        {
            sz = (float)Math.Sqrt(fTrackBallRadius * fTrackBallRadius - d2 * d2);
        }
        else                                                         // On hyperbola
        {
            sz = (fTrackBallRadius * fTrackBallRadius) / (2.0f * d2);
        }

        // Get two points on trackball's sphere
        Vector3 p1 = new Vector3(xpos, ypos, sz);
        Vector3 p2 = new Vector3(0.0f, 0.0f, fTrackBallRadius);

        // Get axis of rotation, which is cross product of p1 and p2
        Vector3 axis = Vector3.Cross(p1, p2);

        // Calculate angle for the rotation about that axis
        float t = Vector3.Length(Vector3.Subtract(p2, p1)) / (2.0f * fTrackBallRadius);

        if (t > +1.0f)
        {
            t = +1.0f;
        }
        if (t < -1.0f)
        {
            t = -1.0f;
        }
        float fAngle = (float)(2.0f * Math.Asin(t));

        // Convert axis to quaternion
        return(Quaternion.RotationAxis(axis, fAngle));
    }
Ejemplo n.º 5
0
        public Input(Form form)
        {
            this.form = form;
            form.KeyDown += new KeyEventHandler(form_KeyDown);
            form.KeyUp += new KeyEventHandler(form_KeyUp);
            form.MouseDown += new MouseEventHandler(form_MouseDown);
            form.MouseMove += new MouseEventHandler(form_MouseMove);
            form.MouseUp += new MouseEventHandler(form_MouseUp);
            form.MouseWheel += new MouseEventHandler(form_MouseWheel);

            KeysDown = new List<Keys>();
            KeysPressed = new List<Keys>();
            KeysReleased = new List<Keys>();
            MousePoint = form.PointToClient(Cursor.Position);
            MouseWheelDelta = 0;
        }
Ejemplo n.º 6
0
        public static string SetJsonInformation(Form form, Stopwatch stopWatch, DateTime startTime)
        {
            // Get current time
            m_CurrenTime = DateTime.Now;

            // Evaluate running time
            m_TimeElasped = m_CurrenTime.Subtract(startTime);

            // Current cursor position.
            Point relativePoint = form.PointToClient(Cursor.Position);

            // Set time stamp
            //TODO: Use GetTimeStamp method.
            string timeStamp = m_TimeElasped.ToString();

            string strToReturn = SetJsonFormat(relativePoint.X, relativePoint.Y, timeStamp);
            return strToReturn;
        }
Ejemplo n.º 7
0
        private void m_mthShowListView()
        {
            Point pt = this.Location;

            pt = this.Parent.PointToScreen(pt);
            int intHeight = this.Parent.Height;

            if (pt.Y < intHeight - m_objListView.Height)
            {
                pt = new Point(pt.X, pt.Y + this.Height);
            }
            else
            {
                pt = new Point(pt.X, pt.Y - m_objListView.Height);
            }
            pt = m_objForm.PointToClient(pt);
            m_objListView.Location = pt;
            m_objListView.Visible  = true;
            m_objListView.BringToFront();
            m_objListView.Focus();
        }
Ejemplo n.º 8
0
        public static void Clip(Processor processor)
        {
            Control.CheckForIllegalCrossThreadCalls = false;

            var clipForm = new Form
            {
                FormBorderStyle = FormBorderStyle.None,
                BackColor = Color.Black,
                Opacity = 0.25,
                ShowInTaskbar = false,
                TopMost = true
            };

            Label sizeLabel;
            clipForm.Controls.Add(sizeLabel = new Label
            {
                AutoSize = false,
                Size = new Size(90, 13),
                Left = clipForm.Width - 75,
                Top = clipForm.Height - 55,
                Anchor = (AnchorStyles.Bottom | AnchorStyles.Right),
                ForeColor = Color.White
            });

            List<Form> forms = new List<Form>();
            foreach (Screen screen in Screen.AllScreens)
            {
                var screenForm = new Form
                {
                    Bounds = screen.Bounds,
                    StartPosition = FormStartPosition.Manual,
                    WindowState = FormWindowState.Maximized,
                    FormBorderStyle = FormBorderStyle.None,
                    Opacity = 0.01,
                    Cursor = Cursors.Cross,
                    ShowInTaskbar = false,
                    TopMost = true
                };
                PictureBox screenImage;
                screenForm.Controls.Add(screenImage = new PictureBox
                {
                    Dock = DockStyle.Fill,
                    Image = GetScreenshot(screen),
                });
                screenForm.Show();
                screenForm.Focus();
                forms.Add(screenForm);

                new Thread(() =>
                {
                    Thread.Sleep(50);
                    screenForm.Opacity = 1.0;
                }).Start();

                screenImage.MouseDown += (s, e) =>
                {
                    var cursorColor = GetColor(screenImage, e.Location);
                    clipForm.BackColor = cursorColor.ToArgb() > Color.Black.ToArgb() / 2 ? Color.Black : Color.White;
                    sizeLabel.ForeColor = cursorColor.ToArgb() > Color.Black.ToArgb() / 2 ? Color.White : Color.Black;
                };

                screenImage.MouseDown += (s, e) =>
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        _selectingArea = true;
                        _startPoint = screenImage.PointToScreen(e.Location);
                        clipForm.Location = _startPoint;
                        clipForm.Size = new Size(1, 1);
                        clipForm.Show();
                    }
                };

                screenImage.MouseMove += (s, e) =>
                {
                    if (_selectingArea)
                    {
                        var newPoint = screenImage.PointToScreen(e.Location);
                        var point = new Point(Math.Min(newPoint.X, _startPoint.X), Math.Min(newPoint.Y, _startPoint.Y));
                        var size = new Size(Math.Max(newPoint.X, _startPoint.X) - point.X, Math.Max(newPoint.Y, _startPoint.Y) - point.Y);
                        if (clipForm.Location != point) clipForm.Location = point;
                        clipForm.Size = size;
                        sizeLabel.Text = size.Width + " x " + size.Height;
                    }
                };

                screenImage.MouseUp += (s, e) =>
                {
                    _selectingArea = false;
                    clipForm.Close();

                    forms.ForEach(f => f.Visible = false); // uncomment for debug

                    Bitmap bitmap;
                    if (screen.Bounds.Contains(clipForm.Bounds))
                        bitmap = GetClip(screenImage.Image, new Rectangle(screenForm.PointToClient(clipForm.Location), clipForm.Size));
                    else bitmap = Collage(forms, clipForm.Location, clipForm.Size);

                    forms.ForEach(f => f.Close());

                    if (bitmap.Size.Width < 15 || bitmap.Size.Height < 15) Terminate(); //too small to see
                    processor.Process(bitmap);
                };

                clipForm.KeyDown += (s, e) => Escape(e);
                screenForm.KeyDown += (s, e) => Escape(e);
                screenImage.KeyDown += (s, e) => Escape(e);
            }
        }
Ejemplo n.º 9
0
 public Vector2 GetCurrPosition( Form hWindow )
 {
     var posRel = hWindow.PointToClient(new Point((int)m_CurrPos.X, (int)m_CurrPos.Y));
     return new Vector2(posRel.X, posRel.Y);
 }
Ejemplo n.º 10
0
 protected virtual void NCPointToClient(ref int x, ref int y)
 {
     form.PointToClient(ref x, ref y);
     NCClientToNC(ref x, ref y);
 }
Ejemplo n.º 11
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 ();
		}
Ejemplo n.º 12
0
            public void Draw(Form popup)
            {
                //determine popup position
                int max = targetWnd.Top + target.Top;

                Position pos = Position.Top;
                int resX = Screen.PrimaryScreen.Bounds.Width, resY = Screen.PrimaryScreen.Bounds.Height;

                if (resY - (targetWnd.Top + target.Top) > max)
                {
                    max = resY - (targetWnd.Top + target.Top);
                    pos = Position.Bottom;
                }

                if (targetWnd.Left + target.Left > max)
                {
                    max = targetWnd.Left + target.Left;
                    pos = Position.Left;
                }

                if (resX - (targetWnd.Left + target.Left) > max)
                {
                    max = resX - (targetWnd.Left + target.Left);
                    pos = Position.Right;
                }

                //position popup
                Label lbl = (Label)popup.Controls["lbl"];
                Button buttAdv = (Button)popup.Controls["buttAdv"];
                Panel butts = (Panel)popup.Controls["butts"];

                Rectangle back = new Rectangle();
                Point a = new Point(), coords = new Point();
                Size pointSize = getPointerSize(pos, lbl, buttAdv, butts);

                switch (pos)
                {
                    case Position.Top:
                        lbl.Left = 7;
                        lbl.Top = 5;
                        positionButtons(lbl, buttAdv, butts);

                        back = new Rectangle(new Point(2, 2), getBackSize(lbl, buttAdv, butts));
                        a = new Point(back.Left + back.Width / 2, back.Top + back.Height);

                        popup.Width = Math.Max(5 + lbl.Width + 5, 12 + target.Width + 12);
                        popup.Height = 7 + lbl.Height + 5 + (buttAdv.Visible ? buttAdv.Height + 5 : 0) + butts.Height + 7 + 150 + 7 + target.Height + 7;

                        coords = target.PointToScreen(new Point(target.Width / 2, 0));
                        popup.Location = checkBounds(popup, coords.X + target.Width / 2 + 12 - popup.Width, coords.Y + target.Height + 7 - popup.Height);
                        break;
                    case Position.Bottom:
                        lbl.Left = 7;
                        lbl.Top = pointSize.Height + 5;
                        positionButtons(lbl, buttAdv, butts);

                        back = new Rectangle(new Point(2, pointSize.Height - 2), getBackSize(lbl, buttAdv, butts));
                        a = new Point(back.Left + back.Width / 2, back.Top);

                        popup.Width = back.Width;
                        popup.Height = pointSize.Height + back.Height;

                        coords = target.PointToScreen(new Point(target.Width / 2, target.Height));
                        popup.Location = checkBounds(popup, coords.X - popup.Width / 2, coords.Y - target.Height - 5);
                        break;
                    case Position.Left:
                        lbl.Left = 7;
                        lbl.Top = 5;
                        positionButtons(lbl, buttAdv, butts);

                        back = new Rectangle(new Point(0, 2), getBackSize(lbl, buttAdv, butts));
                        a = new Point(back.Left + back.Width, back.Top + back.Height / 2);

                        popup.Width = back.Width + pointSize.Width;
                        popup.Height = pointSize.Height;

                        coords = target.PointToScreen(new Point(0, target.Height / 2));
                        popup.Location = checkBounds(popup, coords.X + target.Width + 12 - popup.Width, coords.Y - target.Height / 2 - 5);
                        break;
                    case Position.Right:
                        lbl.Left = pointSize.Width + 5;
                        lbl.Top = 5;
                        positionButtons(lbl, buttAdv, butts);

                        back = new Rectangle(new Point(pointSize.Width - 2, 2), getBackSize(lbl, buttAdv, butts));
                        a = new Point(back.Left, back.Top + back.Height / 2);

                        popup.Width = pointSize.Width + back.Width;
                        popup.Height = pointSize.Height;

                        coords = target.PointToScreen(new Point(target.Width, target.Height / 2));
                        popup.Location = checkBounds(popup, coords.X - target.Width - 12, coords.Y - target.Height / 2 - 5);
                        break;
                }

                Point b = popup.PointToClient(coords);

                //draw
                Graphics gfx = popup.CreateGraphics();
                gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                gfx.Clear(Color.White);

                gfx.FillRectangle(new SolidBrush(Color.FromArgb(50, Color.Gray)), back);

                if (pos == Position.Top || pos == Position.Bottom)
                    back.Width -= 4;

                gfx.DrawRectangle(new Pen(Color.Black, 2), back);

                switch (sel)
                {
                    case Selection.Rectangle:
                        coords = popup.PointToClient(target.PointToScreen(Point.Empty));

                        if (target != targetWnd)
                            gfx.DrawRectangle(new Pen(Color.Black, 2), coords.X, coords.Y, target.Width, target.Height);
                        else
                            gfx.DrawRectangle(new Pen(Color.Black, 2), coords.X - 8, coords.Y - 30, target.Width, target.Height);
                        break;
                    case Selection.Circle:
                        coords = popup.PointToClient(target.PointToScreen(new Point(-10, -5)));

                        if (target != targetWnd)
                            gfx.DrawEllipse(new Pen(Color.Black, 2), coords.X, coords.Y, target.Width + 20, target.Height + 10);
                        else
                            gfx.DrawEllipse(new Pen(Color.Black, 2), coords.X, coords.Y - 30, target.Width, target.Height);

                        //adjust point b
                        switch (pos)
                        {
                            case Position.Top:
                                b.Y -= 5;
                                break;
                            case Position.Bottom:
                                b.Y += 5;
                                break;
                            case Position.Left:
                                b.X -= 10;
                                break;
                            case Position.Right:
                                b.X += 10;
                                break;
                        }
                        break;
                }

                if (arrow)
                    drawArrow(gfx, a, b);
                else if (line)
                    gfx.DrawLine(new Pen(Color.Black, 4), a, b);
            }
Ejemplo n.º 13
0
        /// <summary>
        /// Starts the form resize from edge.
        /// </summary>
        /// <param name="f">The f.</param>
        /// <param name="result">The result.</param>
        /// <param name="c">The c.</param>
        public static void StartFormResizeFromEdge(System.Windows.Forms.Form f, ResizeResult result, Control c = null)
        {
            var minimum = f is Zeroit.Framework.Form.ModernForm.Forms.ModernForm modernForm ? modernForm.MinimumSize : f.MinimumSize;
            var maximum = f is Zeroit.Framework.Form.ModernForm.Forms.ModernForm form ? form.MaximumSize : f.MaximumSize;
            //Cursor.Clip = Screen.GetWorkingArea(f);
            var curLoc     = f.PointToClient(Cursor.Position);
            var fLoc       = new Point(f.Left, f.Top);
            var w          = f.Width;
            var h          = f.Height;
            var resultEnum = ((ResizeResult)result);

            Action <Object, MouseEventArgs> mouseMove = (s, e) => {
                if (f.WindowState != FormWindowState.Maximized)
                {
                    var changedSize  = (new Size(curLoc) - new Size(e.Location)).Width;
                    var changedSizeH = (new Size(curLoc) - new Size(e.Location)).Height;
                    f.Cursor = HitTestToCursor(result);
                    switch (resultEnum)
                    {
                    case ResizeResult.Left:
                        if (curLoc.X <= Zeroit.Framework.Form.ModernForm.Forms.ModernForm.SizingBorder && ((f.Width + changedSize) >= minimum.Width))
                        {
                            f.Left  -= changedSize;
                            fLoc     = new Point(f.Left, f.Top);
                            f.Width += changedSize;
                            f.Update();
                        }
                        break;

                    case ResizeResult.Right:
                        if (curLoc.X >= minimum.Width - Zeroit.Framework.Form.ModernForm.Forms.ModernForm.SizingBorder)
                        {
                            f.Left  = fLoc.X;
                            curLoc  = f.PointToClient(Cursor.Position);
                            f.Width = w - changedSize;
                            f.Update();
                            w = f.Width;
                        }
                        break;

                    case ResizeResult.Bottom:
                        if (curLoc.Y >= minimum.Height - Zeroit.Framework.Form.ModernForm.Forms.ModernForm.SizingBorder)
                        {
                            f.Top    = fLoc.Y;
                            curLoc   = f.PointToClient(Cursor.Position);
                            f.Height = h - changedSizeH;
                            f.Update();
                            h = f.Height;
                        }
                        break;

                    case ResizeResult.BottomLeft:
                        if (curLoc.X <= Zeroit.Framework.Form.ModernForm.Forms.ModernForm.SizingBorder && curLoc.Y >= minimum.Height - Zeroit.Framework.Form.ModernForm.Forms.ModernForm.SizingBorder && ((f.Width + changedSize) >= minimum.Width))
                        {
                            var ww = e.Location.X - f.Left;
                            var hh = e.Location.Y - f.Bottom;

                            f.Height = f.Bottom + hh;
                            f.Left  -= changedSize;
                            fLoc     = new Point(f.Left, f.Top);
                            f.Width += changedSize;

                            f.Update();
                        }
                        break;

                    case ResizeResult.BottomRight:
                        var ww2 = e.Location.X - f.Right;
                        var hh2 = e.Location.Y - f.Bottom;

                        f.Height = f.Bottom + hh2;

                        fLoc     = new Point(f.Left, f.Top);
                        f.Width += f.Left + ww2;

                        f.Update();

                        break;
                    }
                }
            };
            MouseEventHandler invoke = mouseMove.Invoke;

            f.MouseMove += invoke;
            MouseEventHandler invokeCMove = (s, e) => {
                var pt = f.PointToClient(((Control)s).PointToScreen(e.Location));
                var x  = pt.X;
                var y  = pt.Y;


                invoke(f, new MouseEventArgs(e.Button, e.Clicks, x, y, e.Delta));
            };

            if (c != null)
            {
                c.MouseMove += invokeCMove;
            }



            MouseEventHandler invoke2 = null;

            invoke2 = (s, e) => {
                if (c != null)
                {
                    c.MouseMove -= invokeCMove;
                }
                if (c != null)
                {
                    c.MouseUp -= invoke2;
                }
                f.MouseUp   -= invoke2;
                f.MouseMove -= invoke;
                f.Update();
                //Cursor.Clip = new Rectangle();
            };

            f.MouseUp += invoke2;
            if (c != null)
            {
                c.MouseUp += invoke2;
            }
        }
Ejemplo n.º 14
0
 private bool InForm(Form f, Point screenPoint)
 {
     Point p = f.PointToClient(screenPoint);
     return p.X > 0 && p.X < f.Size.Width && p.Y > 0 && p.Y < f.Size.Height;
 }