请高手给个详细的程序代码! 谢谢 啦
是按钮向各个方向随便移动,, 只要鼠标放到按钮上 按钮就随便移动 谢谢啦 随机移动... 但不能超出windows窗体的边框!
制作WIndous窗体时 怎样使鼠标移动到按钮上时,按钮移动?
答案:2 悬赏:70 手机版
解决时间 2021-02-16 21:03
- 提问者网友:川水往事
- 2021-02-16 00:46
最佳答案
- 五星知识达人网友:玩家
- 2021-02-16 01:20
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;
}
}
全部回答
- 1楼网友:佘樂
- 2021-02-16 01:58
你说呢...
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯