Beispiel #1
0
 /// <summary>
 /// 在选择和添加对像时及时更新属性显示器中的内容
 /// </summary>
 /// <param name="item">要显示属性的对像</param>
 public void SelectedItem(DrawItemBase item)
 {
     if (OnShowProperityInfo != null)
     {
         OnShowProperityInfo(item);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 删除设计器选中的对像
        /// </summary>
        public void DeleteSelectedItem()
        {
            //获取设计器中的对像数量
            DrawItemBase[] drawitems = new DrawItemBase[Items.Count];
            Items.CopyTo(drawitems, 0);//将对像复制一份删除时使用
            foreach (DrawItemBase dib in drawitems)
            {
                //如果对像选择删除
                if (dib.Selected)
                {
                    //Items.UnSelectAll();

                    Items.Remove(dib);
                    //if (dib is DrawText)
                    //{
                    //    textBox.Text = "";
                    //    textBox.Visible = false;
                    //}
                }
            }
            //更新对像
            this.Refresh();
            //删除时触发item更改事件在documentspace中更新对像列表
            if (OnItemChange != null)
            {
                OnItemChange();
            }
        }
Beispiel #3
0
        public override void OnMouseUp(Designer designer, System.Windows.Forms.MouseEventArgs e)
        {
            //如果是区域选择,选中在此区域的对像
            if (selectmode == SelectionMode.NetSelection)
            {
                designer.Items.SelectInRectangle(designer.SelectRectangle);
                selectmode = SelectionMode.None;
                designer.IsDrawSelectRectangle = false;
            }
            //如果是改变大小则结束改变
            if (resizeObject != null)
            {
                resizeObject.Normalize();

                //如果改变对像的尺寸大小
                if (designer.SelectDrawText != null && (resizeObject.GetType().Name == designer.SelectDrawText.GetType().Name))
                {
                    Rectangle rectangle = DrawRectangle.GetNormalizedRectangle((resizeObject as DrawText).Rectangle);
                    designer.textBox.Location = new Point(rectangle.X + 8, rectangle.Y + 7);
                    designer.textBox.Size     = new Size(rectangle.Width - 10, rectangle.Height - 10);
                    // designer.textBox.Focus();
                    //设置当前选中的文本编辑器
                    //在多个编辑切换时,可以知道当前编辑的是哪一个
                }

                resizeObject = null;
            }
            designer.Capture = false;
            designer.Refresh();
        }
Beispiel #4
0
        protected void AddNewObject(Designer designer, DrawItemBase drawitem)
        {
            //在设计器对像列表中加入新的对像
            designer.Items.Add(drawitem);
            //将原来选中的对像设计为未选中
            designer.Items.UnSelectAll();
            //设置新添加的对像为选中状态
            drawitem.Selected = true;

            designer.Capture = true;
            designer.Refresh();
            //new PubUtils().ShowNoteOKMsg(((LablePrint.DrawItem.DrawText)(drawitem)).TextRectangle.Width.ToString());
            designer.ChangeFlage = true;
        }
Beispiel #5
0
 private void Designer_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     //如果是鼠标左键和当前工具是"选择"才执行显示属性或编辑(文本)操作
     if (e.Button == MouseButtons.Left && (activeTool.GetType().Name == typeof(ToolSelector).Name))
     {
         //由于在鼠标点击时控制了鼠标工作区域,如果是双击则不需要控制
         //恢复鼠标的工作区域
         Cursor.Clip = tempCursorPos;
         if (this.Items != null && this.Items.Count > 0)
         {
             //取消所有选择
             this.Items.UnSelectAll();
             int          count = this.Items.Count;
             DrawItemBase item  = null;
             for (int i = 0; i < count; i++)
             {
                 //检查是否有选中的对像
                 if (this.Items[i].HitTest(new Point(e.X, e.Y)) == 0)
                 {
                     item          = this.Items[i]; //获取选中的对像
                     item.Selected = true;          //设置为选中状态
                     //如果绑定了显示属性事件则触发事件
                     if (OnShowProperityInfo != null)
                     {
                         OnShowProperityInfo(item);
                     }
                     //如果是文本编辑则显示出textbox
                     if (item.GetType().Name == typeof(DrawText).Name)
                     {
                         DrawText dt = item as DrawText;
                         textBox.Location = new Point(dt.Rectangle.X + 8, dt.Rectangle.Y + 7);
                         textBox.Size     = new Size(dt.Rectangle.Width - 14, dt.Rectangle.Height - 14);
                         textBox.Font     = dt.TextFont;
                         textBox.Text     = dt.TextValue;
                         textBox.Focus();
                         textBox.Enabled = true;
                         textBox.Visible = true;
                     }
                     this.Refresh();
                     break;
                 }
             }
         }
     }
 }
Beispiel #6
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index > -1 && this.Items.Count > 0)
            {
                e.DrawBackground();

                e.DrawFocusRectangle();
                DrawItemBase item = this.Items[e.Index] as DrawItemBase;
                Graphics     g    = e.Graphics;
                g.DrawImage(item.IconImage, new Rectangle(e.Bounds.X + 15, e.Bounds.Y + 2, 16, 16));


                if (this.SelectedIndex == e.Index)
                {
                    g.DrawString(item.Name + " - " + (e.Index + 1).ToString(), new Font("Verdana", 9), Brushes.White, e.Bounds.X + 36, e.Bounds.Y + 3);
                }
                else
                {
                    g.DrawString(item.Name + " - " + (e.Index + 1).ToString(), new Font("Verdana", 9), Brushes.Blue, e.Bounds.X + 36, e.Bounds.Y + 3);
                }
            }
            // base.OnDrawItem(e);
        }
Beispiel #7
0
 /// <summary>
 /// 将对像的属性显示出来
 /// </summary>
 /// <param name="sender"></param>
 protected void designer1_OnShowProperityInfo(DrawItemBase sender)
 {
     propertyGrid1.SelectedObject = sender;
 }
Beispiel #8
0
        public override void OnMouseDown(Designer designer, System.Windows.Forms.MouseEventArgs e)
        {
            selectmode = SelectionMode.None;
            Point point       = new Point(e.X, e.Y);
            int   selectCount = designer.Items.SelectionCount;

            //如果光标在后柄上,则模式为改变对像的大小
            for (int i = 0; i < selectCount; i++)
            {
                //找到要修改的对像
                DrawItemBase item = designer.Items.GetSelectItem(i);
                if (item == null)
                {
                    continue;
                }
                int handleNumber = item.HitTest(point);
                if (handleNumber > 0)
                {
                    selectmode = SelectionMode.Size;

                    resizeHandle = handleNumber;
                    resizeObject = item;

                    designer.Items.UnSelectAll();

                    resizeObject.Selected = true;
                    break;
                }
            }

            //如果没有选中对像手柄,则检查是否在对像上
            if (selectmode == SelectionMode.None)
            {
                int          itemCount = designer.Items.Count;
                DrawItemBase item      = null;
                for (int i = 0; i < itemCount; i++)
                {
                    if (designer.Items[i].HitTest(point) == 0)
                    {
                        item       = designer.Items[i];
                        selectmode = SelectionMode.Move;
                        designer.Items.UnSelectAll();
                        item.Selected = true;
                        designer.SelectedItem(item);
                        designer.Cursor = Cursors.SizeAll;
                        break;
                    }
                }
            }

            // 如果没有选中对像,则是进行区域选择
            if (selectmode == SelectionMode.None)
            {
                selectmode = SelectionMode.NetSelection;
                designer.Items.UnSelectAll();
                designer.IsDrawSelectRectangle = true;
            }

            lastPoint.X = startPoint.X = e.X;
            lastPoint.Y = startPoint.Y = e.Y;

            designer.Capture = true;

            designer.SelectRectangle = GetNormalizedRectangle(startPoint.X, startPoint.Y, lastPoint.X, lastPoint.Y);
            designer.Refresh();
        }