الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تحريك كائن على الفورم

مغلق
بدأه الإبراهيمي في 28 يوليو 2006 · 4 رد · 660 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

كيف يمكنني أن أحرك كائن ما على الفورم بواسطة الفأرة

تحريك command button مثلا

#2

private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)

{

if(e.Button==MouseButtons.Left)

{

button1.Top =e.Y ;

button1.Left=e.X ;

}

}

#3

جرب هذا الكود:

		private bool boolMouseDown = false;
		private System.Drawing.Point MouseLocation;


		void btnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			boolMouseDown = true;
			MouseLocation.X = e.X;
			MouseLocation.Y = e.Y;
		}

		void btnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (boolMouseDown)
			{
			int x = btn.Location.X + e.Location.X - MouseLocation.X;
			int y = btn.Location.Y + e.Location.Y - MouseLocation.Y;
			btn.Location = new System.Drawing.Point(x, y);
			}

		}

		void btnMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			boolMouseDown = false;
		}

رأس الحكمة الإيمان بالله

#4

شكرا جزيلا

بارك الله فيكما.

#5

الحل هو كالتالي

لتحريك Command button

private void button1_MouseMove(object sender, MouseEventArgs e)

{

if (e.Button == MouseButtons.Left)

{

button1.Left = button1.Left + e.X - button1.Width / 2;

button1.Top = button1.Top + e.Y - button1.Height / 2;

}

}

هذا هو المثال

move_object.zip

هذا الموضوع مغلق.

مواضيع مشابهة