震动问题

coolio1 2009-11-17 08:01:07
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace shake_shake
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnsend_Click(object sender, EventArgs e)
{
txtget.Text = txtsend.Text + System.Environment.NewLine +System.DateTime.Now.Day;
txtsend.Clear();
}

private void btnshake_Click(object sender, EventArgs e)
{
int recordx = this.Left;
int recordy = this.Top;
Random raline = new Random();
for (int i = 0; i < 1000; i++)
{
int x = raline.Next(recordx);//别人说这里是rand。不懂什么意思
int y = raline.Next(recordy);
if (x % 2 == 0)
{
this.Left=this.Left + x;
}
else
{
this.Left = this.Left - x ;
}
if (y % 2 == 0)
{
this.Top = this.Top +y;
}
else
{
this.Top = this.Top - y;
}
//System.Threading.Thread.Sleep(1);//不知道这句什么意思
}
this.Left = recordx;
this.Top = recordy;

}

}
}

//问题1:为什么震动的时候,窗体在屏幕中不停乱跑,不像qq震动一样呢?问题2:int x = raline.Next(recordx);//别人说这里是rand。不懂什么意思/。问题3:System.Threading.Thread.Sleep(1);//不知道这句什么意思
...全文
76 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
coolio1 2009-11-17
  • 打赏
  • 举报
回复
非常感谢啊,我已经自己弄懂了。哈
liherun 2009-11-17
  • 打赏
  • 举报
回复
可以不带参数的,不过范围应该超过Int32 最好还是给个种子
coolio1 2009-11-17
  • 打赏
  • 举报
回复
int x = raline.Next()这样不带参数的可以吗?

停止的毫秒数是不是代表震动的频率呢?
liherun 2009-11-17
  • 打赏
  • 举报
回复
问题1: 你写的代码就是乱跑的
问题2: Random raline = new Random(); 是定义随即数的
int x = raline.Next(recordx); 就是随机的
问题3: 让程序停止1毫秒


110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧