/* tool drag - drop event , when left mouse down */ private void module_drag_MouseDown(object sender, MouseEventArgs e) { /* * Make my life easier, don't ask why ? */ GroupBox module_sel = sender as GroupBox; /* * check if mouse click is left mouse, * are you going to drag this tool by right mouse ? * Really ? */ if (e.Button == MouseButtons.Left) { isDragged = true; drag_Loc = module_sel.Location; Point ptStartPosition = module_sel.PointToScreen(new Point(e.X, e.Y)); ptOffset = new Point(); ptOffset.X = module_sel.Location.X - ptStartPosition.X; ptOffset.Y = module_sel.Location.Y - ptStartPosition.Y; } else { isDragged = false; // Is it not obvious why ? } }
public SetupControl() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // TODO: Add any initialization after the InitializeComponent call _oPopup.StartPosition = FormStartPosition.Manual; _oPopup.Location = grpSimulation.PointToScreen(new Point(0, 0)); txtEnd.TextChanged += UpdateConfig; txtMaxSteps.TextChanged += UpdateConfig; txtNumBifurcationsToTrack.TextChanged += UpdateConfig; txtStart.TextChanged += UpdateConfig; radBackward.CheckedChanged += UpdateConfig; radForward.CheckedChanged += UpdateConfig; }
/* tool drag - drop event , when dragging */ private void module_drag_MouseMove(object sender, MouseEventArgs e) { /* * Make my life easier, don't ask why ? */ GroupBox module_sel = sender as GroupBox; /* * this is where magic happen, relocate the * tool according to the location of the mouse */ if (isDragged) { Point newPoint = module_sel.PointToScreen(new Point(e.X, e.Y)); newPoint.Offset(ptOffset); module_sel.Location = newPoint; } }
//把相对与control控件的坐标,转换成相对于窗体的坐标。 private Point getPointToForm(Point p) { return(this.PointToClient(grp.PointToScreen(p))); }