Background
Many times I have seen that many programmer creates
designable hearder for their windows forms but then donsen't have the fesility
of moving like predifined windows forms,
but after reading this article this is simple to create a .dll form
header movable.
You can create any control movable on the form by this code…
Okay lets start to do this___
First step
First you
have to create a Header by Windows Control Library in Visual Studio / any
version.
After creating
header just use this in your windows project as a usercontrol from toolbox
after importing.
Interface

Coding
Here is the
code in C#
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; } } } |
Now here you
are seeing this form header is different and also movable
For further
help contact me : I will be happy to help you.
Thanks
Nikhil Kumar

Join the conversation! Your thoughts help the community grow.