Ejemplo n.º 1
0
 protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
 {
     base.OnMouseUp(e);
     m_mousedownPos             = Point.Empty;
     m_selectControlPressedType = SizeType.SizeNone;
     if (!ModifierKeys.HasFlag(Keys.Control) && m_originControl != null)
     {
         SelectControl = m_originControl;
     }
     m_copyControl   = null;
     m_originControl = null;
 }
Ejemplo n.º 2
0
 protected override void OnKeyUp(KeyEventArgs e)
 {
     base.OnKeyUp(e);
     switch (e.KeyCode)
     {
     case Keys.ControlKey:
         if (MouseButtons == MouseButtons.Left)
         {
             var orgControl = GetChildAtPoint(PointToClient(m_mousedownPos));
             if (orgControl != null)
             {
                 orgControl.Rectangle = m_selectControl.Rectangle;
                 //SelectControl = orgControl;
                 m_selectControl = orgControl;
             }
             if (m_copyControl != null)
             {
                 Controls.Remove(m_copyControl);
             }
         }
         m_copyControl = null;
         break;
     }
 }
Ejemplo n.º 3
0
        protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseMove(e);
            //更改鼠标箭头
            if (m_selectControl != null && e.Button.Equals(MouseButtons.None))
            {
                if (GetCornerRect(SizeType.SizeLT).Contains(e.Location) || GetCornerRect(SizeType.SizeRB).Contains(e.Location))
                {
                    this.Cursor = Cursors.SizeNWSE;
                }
                else if (GetCornerRect(SizeType.SizeL).Contains(e.Location) || GetCornerRect(SizeType.SizeR).Contains(e.Location))
                {
                    this.Cursor = Cursors.SizeWE;
                }
                else if (GetCornerRect(SizeType.SizeLB).Contains(e.Location) || GetCornerRect(SizeType.SizeRT).Contains(e.Location))
                {
                    this.Cursor = Cursors.SizeNESW;
                }
                else if (GetCornerRect(SizeType.SizeT).Contains(e.Location) || GetCornerRect(SizeType.SizeB).Contains(e.Location))
                {
                    this.Cursor = Cursors.SizeNS;
                }
                else
                {
                    this.Cursor = Cursors.Default;
                }
            }

            //调整尺寸
            if (e.Button.HasFlag(System.Windows.Forms.MouseButtons.Left) && m_selectControl != null)
            {
                switch (m_selectControlPressedType)
                {
                case SizeType.SizeLT:
                    m_selectControl.Left   = m_selectControlRect.Left - m_mousedownPos.X + MousePosition.X;
                    m_selectControl.Top    = m_selectControlRect.Top - m_mousedownPos.Y + MousePosition.Y;
                    m_selectControl.Width  = m_selectControlRect.Width + m_mousedownPos.X - MousePosition.X;
                    m_selectControl.Height = m_selectControlRect.Height + m_mousedownPos.Y - MousePosition.Y;
                    break;

                case SizeType.SizeL:
                    m_selectControl.Left  = m_selectControlRect.Left - m_mousedownPos.X + MousePosition.X;
                    m_selectControl.Width = m_selectControlRect.Width + m_mousedownPos.X - MousePosition.X;
                    break;

                case SizeType.SizeLB:
                    m_selectControl.Left   = m_selectControlRect.Left - m_mousedownPos.X + MousePosition.X;
                    m_selectControl.Width  = m_selectControlRect.Width + m_mousedownPos.X - MousePosition.X;
                    m_selectControl.Height = m_selectControlRect.Height - m_mousedownPos.Y + MousePosition.Y;
                    break;

                case SizeType.SizeT:
                    m_selectControl.Top    = m_selectControlRect.Top - m_mousedownPos.Y + MousePosition.Y;
                    m_selectControl.Height = m_selectControlRect.Height + m_mousedownPos.Y - MousePosition.Y;
                    break;

                case SizeType.SizeB:
                    m_selectControl.Height = m_selectControlRect.Height - m_mousedownPos.Y + MousePosition.Y;
                    break;

                case SizeType.SizeRT:
                    m_selectControl.Top    = m_selectControlRect.Top - m_mousedownPos.Y + MousePosition.Y;
                    m_selectControl.Width  = m_selectControlRect.Width - m_mousedownPos.X + MousePosition.X;
                    m_selectControl.Height = m_selectControlRect.Height + m_mousedownPos.Y - MousePosition.Y;
                    break;

                case SizeType.SizeR:
                    m_selectControl.Width = m_selectControlRect.Width - m_mousedownPos.X + MousePosition.X;
                    break;

                case SizeType.SizeRB:
                    m_selectControl.Width  = m_selectControlRect.Width - m_mousedownPos.X + MousePosition.X;
                    m_selectControl.Height = m_selectControlRect.Height - m_mousedownPos.Y + MousePosition.Y;
                    break;

                case SizeType.SizeM:
                    //支持复制
                    if (ModifierKeys.HasFlag(Keys.Control))
                    {
                        if (/*m_selectControl is Controls.wLabel &&*/ m_copyControl == null)
                        {
                            m_originControl = m_selectControl;
                            m_copyControl   = m_selectControl.Clone() as Controls.wControl;
//
                            m_copyControl.Rectangle   = m_selectControl.Rectangle;
                            m_selectControl.Rectangle = m_selectControlRect;
//
                            Controls.Add(m_copyControl);
                            SelectControl = m_copyControl;
                            //m_selectControl=m_copyControl;
                        }
                    }
                    m_selectControl.Left = m_selectControlRect.Left - m_mousedownPos.X + MousePosition.X;
                    m_selectControl.Top  = m_selectControlRect.Top - m_mousedownPos.Y + MousePosition.Y;

                    break;
                }
                Refresh();
            }
        }
Ejemplo n.º 4
0
        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseDown(e);
            m_mousedownPos = MousePosition;          // e.Location;
            if (SelectControl != null)
            {
                m_selectControlRect = m_selectControl.Rectangle;
            }

            if (SelectControl != null)
            {
                var pos = this.PointToClient(MousePosition);
                if (GetCornerRect(SizeType.SizeLT).Contains(pos))
                {
                    m_selectControlPressedType = SizeType.SizeLT;
                }
                else if (GetCornerRect(SizeType.SizeL).Contains(pos))
                {
                    m_selectControlPressedType = SizeType.SizeL;
                }
                else if (GetCornerRect(SizeType.SizeLB).Contains(pos))
                {
                    m_selectControlPressedType = SizeType.SizeLB;
                }
                else if (GetCornerRect(SizeType.SizeT).Contains(pos))
                {
                    m_selectControlPressedType = SizeType.SizeT;
                }
                else if (GetCornerRect(SizeType.SizeB).Contains(pos))
                {
                    m_selectControlPressedType = SizeType.SizeB;
                }
                else if (GetCornerRect(SizeType.SizeRT).Contains(pos))
                {
                    m_selectControlPressedType = SizeType.SizeRT;
                }
                else if (GetCornerRect(SizeType.SizeR).Contains(pos))
                {
                    m_selectControlPressedType = SizeType.SizeR;
                }
                else if (GetCornerRect(SizeType.SizeRB).Contains(pos))
                {
                    m_selectControlPressedType = SizeType.SizeRB;
                }
                else if (GetCornerRect(SizeType.SizeM).Contains(pos))
                {
                    m_selectControlPressedType = SizeType.SizeM;
                }
                else
                {
                    m_selectControlPressedType = SizeType.SizeNone;
                }
                Refresh();
            }
            else
            {
                m_selectControlPressedType = SizeType.SizeNone;
            }

            if (m_selectControlPressedType == SizeType.SizeNone)
            {
                SelectControl = GetChildAtPoint(PointToClient(m_mousedownPos));
                Controls.SetFront(SelectControl);
                Refresh();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 清除选中
 /// </summary>
 protected void ClearSelect()
 {
     SelectControl = null;
     m_selectControlPressedType = SizeType.SizeNone;
     m_selectControlRect        = Rectangle.Empty;
 }
Ejemplo n.º 6
0
        public void Init(System.Xml.XmlDocument doc)
        {
            Controls.Clear();
            var layout = doc.SelectSingleNode("/layout");

            if (layout == null)
            {
                throw new Exception("无效参数");
            }
            if (layout.Attributes["version"].Value != version)
            {
                throw new Exception("文件版本不一致");
            }
            var author = layout.SelectSingleNode("property/author");

            this.Author = author.Attributes["name"].Value;

            var canvas = layout.SelectSingleNode("property/canvas");

            this.SizeF = new SizeF(float.Parse(canvas.Attributes["width"].Value), float.Parse(canvas.Attributes["height"].Value));

            var background = layout.SelectSingleNode("property/background");

            if (background != null)
            {
                this.BackgroundRect = new Rectangle(
                    int.Parse(background.Attributes["left"].Value),
                    int.Parse(background.Attributes["top"].Value),
                    int.Parse(background.Attributes["width"].Value),
                    int.Parse(background.Attributes["height"].Value)
                    );
                this.BackgroundPath = background.Attributes["src"].Value;
                this.ShowBackground = bool.Parse(background.Attributes["visible"].Value);
            }
            else
            {
                this.BackgroundPath = string.Empty;
            }

            var datetime = layout.SelectSingleNode("property/datetime");

            this.CreateTime = DateTime.Parse(datetime.Attributes["createtime"].Value);

            var items = layout.SelectSingleNode("items");

            foreach (System.Xml.XmlNode item in items.ChildNodes)
            {
                Controls.wControl ctl = null;
                switch (item.Name)
                {
                case "label":
                    ctl = new Controls.wLabel(item);
                    break;

                case "image":
                    ctl = new Controls.wImage(item);
                    break;

                case "barcode":
                    ctl = new Controls.wBarcode(item);
                    break;

                case "qrcoder":
                    ctl = new Controls.wQRCoder(item);
                    break;

                case "table":
                    ctl = new Controls.wTable(item);
                    break;
                }
                if (ctl != null)
                {
                    this.Controls.Add(ctl);
                }
            }
            SelectControl = null;
            Refresh();
        }