السلام عليكم
كيف يمكنني أن أحرك كائن ما على الفورم بواسطة الفأرة
تحريك command button مثلا
السلام عليكم
كيف يمكنني أن أحرك كائن ما على الفورم بواسطة الفأرة
تحريك command button مثلا
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
button1.Top =e.Y ;
button1.Left=e.X ;
}
}
سبحانه الله وبحمده سبحانه الله العظيم
if (You Love ArabTeam2000 ) MessageBox.Show("All ArabTeam2000 Love You"); else MessageBox.Show("go to your mama"); جرب هذا الكود:
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;
}رأس الحكمة الإيمان بالله
شكرا جزيلا
بارك الله فيكما.
الحل هو كالتالي
لتحريك 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;
}
}
هذا هو المثال
هذا الموضوع مغلق.