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;
}
4 comments:
Excellent example. I knew what I was trying to do.. I just couldnt put it into code. Thank You.
Thanks.
A lot better than using System.Runtime.InteropServices!!!
Awesome Man....... Keep up the Good Work. U made the Situation soo simple yar.
Thank you !
Simple and easy ...
Post a Comment