using System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
Movable_Form
{
public partial class Form1 : Form
{
public int diff_x;
public int diff_y;
public bool mouse_down = false;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object
sender, MouseEventArgs e)
{
diff_x = Form.MousePosition.X -
Form.ActiveForm.Location.X;
diff_y = Form.MousePosition.Y -
Form.ActiveForm.Location.Y;
mouse_down = true;
}
private void Form1_MouseUp(object
sender, MouseEventArgs e)
{
mouse_down = false;
}
private void button1_Click(object
sender, EventArgs e)
{
Dispose();
this.Close();
}
private void Form1_MouseMove(object
sender, MouseEventArgs e)
{
if (mouse_down == true)
{
Point p = new
Point(MousePosition.X - diff_x, MousePosition.Y - diff_y);
Form.ActiveForm.Location = p;
}
}
private void
pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
diff_x = Form.MousePosition.X -
Form.ActiveForm.Location.X;
diff_y = Form.MousePosition.Y -
Form.ActiveForm.Location.Y;
mouse_down = true;
}
private void
pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (mouse_down == true)
{
Point p = new
Point(MousePosition.X - diff_x, MousePosition.Y - diff_y);
Form.ActiveForm.Location = p;
}
}
private void pictureBox1_MouseUp(object
sender, MouseEventArgs e)
{
mouse_down = false;
}
}
} |