جابجا کردن فرم با کلیک بر روی هر قسمت از آن - با استفاده از توابع API
https://barnamenevis.org/showpo...5&postcount=40
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern int ReleaseCapture();
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
static extern int SendMessage(int hwnd, int wMsg, int wParam, object lParam);
private const int WM_NCLBUTTONDOWN = 161;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle.ToInt32(), WM_NCLBUTTONDOWN, 2, 0);
}
جابجا کردن فرم با کلیک بر روی هر قسمت از آن - بدون استفاده از توابع API
https://barnamenevis.org/showpo...5&postcount=52
private bool dragging;
private Point pointClicked;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Turn drag mode on and store the point clicked.
dragging = true;
pointClicked = new Point(e.X, e.Y);
}
else
{
dragging = false;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{
Point pointMoveTo;
// Find the current mouse position in screen coordinates.
pointMoveTo = this.PointToScreen(new Point(e.X, e.Y));
// Compensate for the position the control was clicked.
pointMoveTo.Offset(-pointClicked.X, -pointClicked.Y);
// Move the form.
this.Location = pointMoveTo;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
dragging = false;
}