I'm working on making a program that has no control box, because I don't want one. I am trying to make it so that when I click any area that is not a control, it will move. This is the code I have so far:
public Form1()
{
InitializeComponent();
BackColor = Color.linen;
TransparencyKey = Color.Linen;
}
bool canMove = false;
int mouseX;
int mouseY;
public void MoveForm()
{
mouseX = MousePosition.X - Form1.ActiveForm.Location.X;
mouseY = MousePosition.Y - Form1.ActiveForm.Location.Y;
Form1.ActiveForm.Location = new Point(mouseX, mouseY);
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
canMove = true;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (canMove)
MoveForm();
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
canMove = false;
}
That works for moving, but if the form is at an edge, it will not show up right. Another thing it does, is flashes when it is getting dragged.
Is there any way I can correctly do this?