/// <summary> /// 鼠标弹起事件:让自定义的边框出现 /// </summary> void MouseUp(object sender, MouseEventArgs e) { if (!_isOpenDrag) { return; } Control ct = sender as Control; ct.Refresh(); if (_fc != null) { _fc.Visible = true; _fc.Draw(); DragControlInfo dci = null; if (ct.Tag == null) { dci = new DragControlInfo(); dci.Name = ct.Name; dci.ParentName = ct.Parent.Name; } else { dci = ct.Tag as DragControlInfo; } dci.Location = ct.Location; dci.Size = ct.Size; ct.Tag = dci; } }
/// <summary> /// 控件移动 /// </summary> private void ControlMove() { cPoint = Cursor.Position; int x = cPoint.X - pPoint.X; int y = cPoint.Y - pPoint.Y; switch (this.mpoc) { case MousePosOnCtrl.TOP: if (baseControl.Height - y > MinHeight) { baseControl.Top += y; baseControl.Height -= y; } else { baseControl.Top -= MinHeight - baseControl.Height; baseControl.Height = MinHeight; } break; case MousePosOnCtrl.BOTTOM: if (baseControl.Height + y > MinHeight) { baseControl.Height += y; } else { baseControl.Height = MinHeight; } break; case MousePosOnCtrl.LEFT: if (baseControl.Width - x > MinWidth) { baseControl.Left += x; baseControl.Width -= x; } else { baseControl.Left -= MinWidth - baseControl.Width; baseControl.Width = MinWidth; } break; case MousePosOnCtrl.RIGHT: if (baseControl.Width + x > MinWidth) { baseControl.Width += x; } else { baseControl.Width = MinWidth; } break; case MousePosOnCtrl.TOPLEFT: if (baseControl.Height - y > MinHeight) { baseControl.Top += y; baseControl.Height -= y; } else { baseControl.Top -= MinHeight - baseControl.Height; baseControl.Height = MinHeight; } if (baseControl.Width - x > MinWidth) { baseControl.Left += x; baseControl.Width -= x; } else { baseControl.Left -= MinWidth - baseControl.Width; baseControl.Width = MinWidth; } break; case MousePosOnCtrl.TOPRIGHT: if (baseControl.Height - y > MinHeight) { baseControl.Top += y; baseControl.Height -= y; } else { baseControl.Top -= MinHeight - baseControl.Height; baseControl.Height = MinHeight; } if (baseControl.Width + x > MinWidth) { baseControl.Width += x; } else { baseControl.Width = MinWidth; } break; case MousePosOnCtrl.BOTTOMLEFT: if (baseControl.Height + y > MinHeight) { baseControl.Height += y; } else { baseControl.Height = MinHeight; } if (baseControl.Width - x > MinWidth) { baseControl.Left += x; baseControl.Width -= x; } else { baseControl.Left -= MinWidth - baseControl.Width; baseControl.Width = MinWidth; } break; case MousePosOnCtrl.BOTTOMRIGHT: if (baseControl.Height + y > MinHeight) { baseControl.Height += y; } else { baseControl.Height = MinHeight; } if (baseControl.Width + x > MinWidth) { baseControl.Width += x; } else { baseControl.Width = MinWidth; } break; } pPoint = Cursor.Position; DragControlInfo dci = null; if (baseControl.Tag == null) { dci = new DragControlInfo(); dci.Name = baseControl.Name; dci.ParentName = baseControl.Parent.Name; } else { dci = baseControl.Tag as DragControlInfo; } dci.Location = baseControl.Location; dci.Size = baseControl.Size; baseControl.Tag = dci; }