How to make a form without a title bar movable?
This is a common request in programming forums, and here is a simple solution that depends on handling mouse down and mouse move events:
public partial class Form1 : Form
{
int m_PrevX;
int m_PrevY;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
Left = Left + (e.X - m_PrevX);
Top = Top + (e.Y - m_PrevY);
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button!=MouseButtons.Left)
return;
m_PrevX = e.X;
m_PrevY = e.Y;
}