So I am trying to make a little utility for managing my screens, I want to add a screen rearrangement system like in windows, see here:
,
I already have code worked out for getting and setting the exact screen coordinates I need, however I need to work out some sort of rearrangement dragging system that "snaps" to position like the windows implementation.
so far I have made some basic strides towards this, before coming to the realization the snapping will be a bit challenging, so here is the code I have so far, and here is an attached screenshot of the program as is. It consists of a panel with 3 panels inside it. For now I would like tips on when the mouse is released and the collision checks are run to snap similarly to windows display rearangment, Just a test bed for now
current code:
private Point MouseDownLocation;
private void panel2_MouseMove(object sender, MouseEventArgs e)
{
var pan = (Panel)sender;
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
pan.Left = e.X + pan.Left - MouseDownLocation.X;
pan.Top = e.Y + pan.Top - MouseDownLocation.Y;
}
}
private void panel2_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
var pan = (Panel)sender;
List<Panel> allpanels = new List<Panel>();
foreach (Panel pancomp in panel1.Controls)
{
if (pancomp == pan)
{
continue;
}
allpanels.Add(pancomp);
}
//var pan = (Panel)sender;
List<Panel> collisions = new List<Panel>();
foreach (Panel pancomp in allpanels)
{
if (pancomp == pan)
{
continue;
}
if (pan.Bounds.IntersectsWith(pancomp.Bounds))
{
//PUSH AWAY
collisions.Add(pancomp);
//listBox1.Items.Add("collided!");//panel2.Location.ToString());
}
}
collisions = collisions;
if (collisions.Count > 0)
{
//WE HAVE COLLISIONS LETS SNAP TO VALID PLACE
//MouseDownLocation
}
else
{
//WE HAVE NO COLLISIONS LETS SNAP TO PLACE
}
}
}
private void panel2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
MouseDownLocation = e.Location;
}
}