فقط کافیه ی پنل بعنوان نوار عنوان اضافه شه و رویدادهای مربوط به درگ هم به اون اضافه بشه:
Form1.zip
Untitled.png
public partial class Form1 : Form
{
private bool drag = false; // determine if we should be moving the form
private Point startPoint = new Point(0, 0); // also for the moving
public Form1()
{
InitializeComponent();
}
void Title_MouseUp(object sender, MouseEventArgs e)
{
this.drag = false;
}
void Title_MouseDown(object sender, MouseEventArgs e)
{
this.startPoint = e.Location;
this.drag = true;
}
void Title_MouseMove(object sender, MouseEventArgs e)
{
if (this.drag)
{ // if we should be dragging it, we need to figure out some movement
Point p1 = new Point(e.X, e.Y);
Point p2 = this.PointToScreen(p1);
Point p3 = new Point(p2.X - this.startPoint.X,
p2.Y - this.startPoint.Y);
this.Location = p3;
}
}
private void Title_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(title.BackColor);
g.DrawString("Title", title.Font, Brushes.White, 2, 2);
}
}