tgoop.com/CsharpWindowsForm/131
Last Update:
بسم الله الرحمن الرحيم
اليوم سوف نشرح طريقة أخرى لكيفية تحريك الفورم في حال كانت خاصية FormBorderStyle=none
الطريقة الاولى التي شرحناها في موضوع Custom Control Box الأداة التي كانت تقوم بتحريك الفورم هي panel وكنا نقوم بكتابة الاكواد المطلوبة في كل دالة حدث
MouseDown,MouseUp,MouseMove
الان شاهد الكود التالي والذي قمنا بكتابته داخل دالة البناء للفورم
int x, y;
public Form1()
{
InitializeComponent();
this.Load += delegate (object Sender, EventArgs E)
{
Button1.MouseDown += delegate (object Send, MouseEventArgs M)
{
this.AllowDrop = true;
y = Cursor.Position.Y - this.DesktopLocation.Y;
x = Cursor.Position.X - this.DesktopLocation.X;
};
};
Button1.MouseUp += delegate (object Send, MouseEventArgs E)
{
AllowDrop = false;
};
Button1.MouseMove += delegate (object Sender, MouseEventArgs E)
{
if (AllowDrop)
{
this.DesktopLocation = new Point(Cursor.Position.X - x, Cursor.Position.Y - y);
}
};
}
الان عندما تضغط على الزر button1 وتقوم بتحريك سوف يتم سحب الفورم من مكان الى اخر
شاهد هذا الكود ايضاً
int x, y;
public Form1()
{
InitializeComponent();
this.Load += delegate (object Sender, EventArgs E)
{
this.MouseDown += delegate (object Send, MouseEventArgs M)
{
this.AllowDrop = true;
y = Cursor.Position.Y - this.DesktopLocation.Y;
x = Cursor.Position.X - this.DesktopLocation.X;
};
};
this.MouseUp += delegate (object Send, MouseEventArgs E)
{
AllowDrop = false;
};
this.MouseMove += delegate (object Sender, MouseEventArgs E)
{
if (AllowDrop)
{
this.DesktopLocation = new Point(Cursor.Position.X - x, Cursor.Position.Y - y);
}
};
}
الان الفورم هو الذي سوف يقوم بتحريك نفسه
عندما تحدث الاحداث التالية MouseDown و MouseMove
الكودين السابقين يعملين سوا كانت الخاصية FormBordeStyle
تساوي أي قيمة
انتهى ...........
BY برمجة تطبيقات الويندوز C# Programming
Share with your friend now:
tgoop.com/CsharpWindowsForm/131