打招呼的家伙。
我新的C#。我想在一个窗口中,以模拟降雪,并一直试图以来相当长的时间来完成它。我已取得Windows窗体的大小800 * 600,并设置其背景颜色为黑色。
我已经使用的系统要求和椭圆绘制,并设法改变它的位置在屏幕上,使用一个计时器。虽然我已经成功地创建一个雪花,我没有能够创建多个雪花。
以下是代码。任何帮助将不胜感激。
在此先感谢。
public partial class MainForm : Form
{
System.Timers.Timer t = new System.Timers.Timer();
Graphics f;
int count = 0;
int inc;
Pen myPen = new Pen(Color.White, 2);
int X = 100;
int Y = 10;
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
t.Start();
t.Interval = 100;
t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
}
private void t_Elapsed(object sender, EventArgs e)
{
snowMove();
if (Y == 550)
{
t.Stop();
}
}
private void snowMove()
{
Random r = new Random();
//int tc = System.Environment.TickCount;
f = this.CreateGraphics();
myPen.Color = Color.White;
f.DrawEllipse(myPen, X, Y, 2, 2);
//while (true)
//{
// if (System.Environment.TickCount - tc > 100) break;
//}
myPen.Color = Color.Black;
f.DrawEllipse(myPen, X, Y, 2, 2);
Y++;
count++;
if (count == 5)
{
if ((r.Next(10) - 5) > 0)
{
inc = +1;
}
else
{
inc = -1;
}
X += inc;
count = 0;
}
myPen.Color = Color.White;
f.DrawEllipse(myPen, X, Y, 2, 2);
}
}
}
[编辑]代码块添加 - OriginalGriff [/编辑]