制作WIndous窗体时 怎样使鼠标移动到按钮上时,按钮移动?
请高手给个详细的程序代码!谢谢啦是按钮向各个方向随便移动,,只要鼠标放到按钮上按钮就随便移动谢谢啦随机移动...但不能超出windows窗体的边框!...
请高手给个详细的程序代码! 谢谢 啦
是按钮向各个方向随便移动,, 只要鼠标放到按钮上 按钮就随便移动 谢谢啦 随机移动... 但不能超出windows窗体的边框! 展开
是按钮向各个方向随便移动,, 只要鼠标放到按钮上 按钮就随便移动 谢谢啦 随机移动... 但不能超出windows窗体的边框! 展开
1个回答
展开全部
private void button1_MouseMove(object sender, MouseEventArgs e)
{
Form form1 = new Form();
int a, b;
System.Random rnd = new System.Random();
a = rnd.Next(5);
b = rnd.Next(200);
switch (a)
{
case 1:
button1.Left = button1.Left - b;
break;
case 2:
button1.Left = button1.Left + b;
break;
case 3:
button1.Top = button1.Top - b;
break;
case 4:
button1.Top = button1.Top + b;
break;
}
if (button1.Left < 0)
{
button1.Left = 0;
}
if (button1.Left + button1.Width > form1.Width)
{
button1.Left = form1.Width - button1.Width;
}
if (button1.Top < 0)
{
button1.Top = 0;
}
if (button1.Top + button1.Height > form1.Height)
{
button1.Top = form1.Height - button1.Height;
}
}
{
Form form1 = new Form();
int a, b;
System.Random rnd = new System.Random();
a = rnd.Next(5);
b = rnd.Next(200);
switch (a)
{
case 1:
button1.Left = button1.Left - b;
break;
case 2:
button1.Left = button1.Left + b;
break;
case 3:
button1.Top = button1.Top - b;
break;
case 4:
button1.Top = button1.Top + b;
break;
}
if (button1.Left < 0)
{
button1.Left = 0;
}
if (button1.Left + button1.Width > form1.Width)
{
button1.Left = form1.Width - button1.Width;
}
if (button1.Top < 0)
{
button1.Top = 0;
}
if (button1.Top + button1.Height > form1.Height)
{
button1.Top = form1.Height - button1.Height;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询