29-09-22, 02:36 PM
اريد المساعدة في عمل زر Button عند تحريك الماوس علية يقوم بالتحرك والهرب في اطراف الفورم ويغير لون خلفية الفورم ولا يمكنك من الضغط علية
private void button3_MouseMove(object sender, MouseEventArgs e)
{
Random r = new Random();
Random b = new Random();
Random g = new Random();
this.BackColor = Color.FromArgb(r.Next(235),b.Next(230),g.Next(200));
Random x = new Random();
Random y = new Random();
button3.Left =(int)(x.Next ( this.Width - button3.Width )) ;
button3.Top = (int)(y.Next (this.Height - button3.Height*2) );
button3.Text = "لا تلحقني، مخطوبة..";
} private readonly Random _random = new Random();
public int RandomNumber(int min, int max)
{
return _random.Next(min, max);
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
this.BackColor = Color.FromArgb(RandomNumber(0, 255), RandomNumber(0, 255), RandomNumber(0, 255));
int frmWidth = this.Width - button1.Width; int frmHeigh = this.Height - button1.Height-40;
button1.Location = new Point(RandomNumber(0, frmWidth), RandomNumber(0, frmHeigh));
button1.RightToLeft = RightToLeft.Yes;
this.FormBorderStyle = FormBorderStyle.Fixed3D;
button1.Text = "لا تلمسني - شايفك..";
}
}<button id="myButton" onmousemove="moveButton()" onmouseout="resetButton()">Button</button>body {
background-color: #f2f2f2;
}
button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #4CAF50;
color: white;
padding: 12px 24px;
border: none;
cursor: default;
}function moveButton() {
var button = document.getElementById("myButton");
var x = Math.floor(Math.random() * window.innerWidth);
var y = Math.floor(Math.random() * window.innerHeight);
button.style.left = x + "px";
button.style.top = y + "px";
document.body.style.backgroundColor = "#" + ((1<<24)*Math.random() | 0).toString(16); // تغيير لون خلفية الصفحة بشكل عشوائي
}
function resetButton() {
var button = document.getElementById("myButton");
button.style.left = "50%";
button.style.top = "50%";
document.body.style.backgroundColor = "#f2f2f2"; // إعادة لون خلفية الصفحة إلى الأصلي
}