protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left) //左键 { bool flag = false; foreach (Control c in DesingerHost.Controls) //遍历控件容器 看是否选中其中某一控件 { Rectangle r = c.Bounds; r = DesingerHost.RectangleToScreen(r); r = this.RectangleToClient(r); Rectangle rr = r; rr.Inflate(10, 10); if (rr.Contains(e.Location)) { recter.Rect = r; _currentCtrl = c; recter.IsForm = false; flag = true; Invalidate2(false); break; } } if (!flag) //没有控件被选中,判断是否选中控件容器 { Rectangle r = DesingerHost.Bounds; r = Parent.RectangleToScreen(r); r = this.RectangleToClient(r); if (r.Contains(e.Location)) { recter.Rect = r; recter.IsForm = true; _currentCtrl = null; Invalidate2(false); } } DragType dt = recter.GetMouseDragType(e.Location); //判断是否可以进行鼠标操作 if (dt != DragType.None) { _mouseDown = true; _firstPoint = e.Location; _dragType = dt; } } base.OnMouseDown(e); }
public MessageFilter(DesingerHost hostFrame, DesingerUI designer) { _thehost = hostFrame; _theDesignerBoard = designer; }