PDA

View Full Version : سوال: چگونه فرمی که FormBorderStyle ان None است را حرکت دهیم .



Jaxon_hacker_black
جمعه 18 بهمن 1392, 21:54 عصر
سلام .
من فرم ویندوز اپم رو None کردم یعنی کنترل باکس و از این چیزا نداره .
FormBorderStyle = None
ولی الان دیگه حرکت نمی کنه . وقتی اجرا می شه فقط یک جا ثابت می ماند . چطور کاری کنم با کلیک برو روی فرم و نگاه داشتن ان کلیک و حرکت موس نرم افزارم هم حرکت کنه ؟

shahin bahari
جمعه 18 بهمن 1392, 22:03 عصر
برای این کار برای فرمتون این 3 تا event رو تعریف کنید:

private void MouseDownEvent(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
downPoint = new Point(e.X, e.Y);
}

private void MouseMoveEvent(object sender, MouseEventArgs e)
{
if (downPoint == Point.Empty)
{
return;
}
Point location = new Point(
this.Left + e.X - downPoint.X,
this.Top + e.Y - downPoint.Y);
this.Location = location;
}

private void MouseUpEvent(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
downPoint = Point.Empty;
}

forodo
شنبه 19 بهمن 1392, 08:22 صبح
سلام
با توابع API هم می تونید این کار رو انجام بدید:

public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(this.Handle, 0xa1, 0x2, 0);
}
}

Jaxon_hacker_black
شنبه 19 بهمن 1392, 13:00 عصر
برای این کار برای فرمتون این 3 تا event رو تعریف کنید:

private void MouseDownEvent(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
downPoint = new Point(e.X, e.Y);
}

private void MouseMoveEvent(object sender, MouseEventArgs e)
{
if (downPoint == Point.Empty)
{
return;
}
Point location = new Point(
this.Left + e.X - downPoint.X,
this.Top + e.Y - downPoint.Y);
this.Location = location;
}

private void MouseUpEvent(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
downPoint = Point.Empty;
}



داداش منظورت از downPoint چیه ؟ ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟