Beispiel #1
0
 /// <summary>Get the standard resize cursor for this box zone value</summary>
 public static Cursor ToCursor(this EBoxZone bz)
 {
     if (bz == EBoxZone.Left || bz == EBoxZone.Right || bz == EBoxZone.LR)
     {
         return(Cursors.SizeWE);
     }
     if (bz == EBoxZone.Top || bz == EBoxZone.Bottom || bz == EBoxZone.TB)
     {
         return(Cursors.SizeNS);
     }
     if (bz == EBoxZone.TL || bz == EBoxZone.BR)
     {
         return(Cursors.SizeNWSE);
     }
     if (bz == EBoxZone.BL || bz == EBoxZone.TR)
     {
         return(Cursors.SizeNESW);
     }
     if (bz == EBoxZone.Centre)
     {
         return(Cursors.SizeAll);
     }
     return(Cursors.Default);
 }
Beispiel #2
0
        /// <summary>Handle mouse messages over 'Target' and perform resizing</summary>
        public bool PreFilterMessage(ref Message m)
        {
            if (m.HWnd == Target.Handle || Win32.IsChild(Target.Handle, m.HWnd))
            {
                switch (m.Msg)
                {
                case Win32.WM_LBUTTONDOWN:
                    #region
                {
                    var pt = Control.MousePosition;
                    m_mask = Mask(pt);
                    if (m_mask != EBoxZone.None)
                    {
                        Target.Cursor  = m_mask.ToCursor();
                        m_grab         = pt;
                        m_size         = Target.Size;
                        m_loc          = Target.Location;
                        Target.Capture = true;
                        return(true);
                    }
                    break;
                }

                    #endregion
                case Win32.WM_MOUSEMOVE:
                    #region
                {
                    var pt = Control.MousePosition;
                    if (m_grab != null)
                    {
                        var mn    = Target.MinimumSize;
                        var mx    = Target.MaximumSize != Size.Empty ? Target.MaximumSize : new Size(int.MaxValue, int.MaxValue);
                        var delta = Point_.Subtract(pt, m_grab.Value);
                        if ((m_mask & EBoxZone.Right) != 0)
                        {
                            Target.Width = Math_.Clamp(m_size.Width + delta.Width, mn.Width, mx.Width);
                        }
                        if ((m_mask & EBoxZone.Bottom) != 0)
                        {
                            Target.Height = Math_.Clamp(m_size.Height + delta.Height, mn.Height, mx.Height);
                        }
                        if ((m_mask & EBoxZone.Left) != 0)
                        {
                            Target.Width = Math_.Clamp(m_size.Width - delta.Width, mn.Width, mx.Width); Target.Left = m_loc.X + m_size.Width - Target.Width;
                        }
                        if ((m_mask & EBoxZone.Top) != 0)
                        {
                            Target.Height = Math_.Clamp(m_size.Height - delta.Height, mn.Height, mx.Height); Target.Top = m_loc.Y + m_size.Height - Target.Height;
                        }
                        return(true);
                    }
                    else if (!Win32.IsChild(Target.Handle, m.HWnd))
                    {
                        var mask = Mask(pt);
                        if (mask != m_mask)
                        {
                            Target.Cursor = mask.ToCursor();
                            m_mask        = mask;
                        }
                    }
                    else
                    {
                        Target.Cursor = Cursors.Default;
                    }
                    break;
                }

                    #endregion
                case Win32.WM_LBUTTONUP:
                    #region
                {
                    if (m_grab != null)
                    {
                        m_grab         = null;
                        Target.Capture = false;
                        return(true);
                    }
                    break;
                }

                    #endregion
                case Win32.WM_MOUSELEAVE:
                    #region
                {
                    m_mask = EBoxZone.None;
                    break;
                }
                    #endregion
                }
            }
            return(false);
        }