hello guys.
I am new to C#. I am trying to simulate snowfall in a window and have been trying to finish it since quite a long time.
I have made a windows form of size 800*600 and set its background color to black.
I have used System.Drawing to draw and ellipse and managed to change its location across the screen using a timer.
Though i have managed to create one snowflake, i have not been able to create multiple snowflakes.
The following is the code. Any help will be grateful.
Thanks in advance.
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();
f = this.CreateGraphics();
myPen.Color = Color.White;
f.DrawEllipse(myPen, X, Y, 2, 2);
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);
}
}
}
[edit]Code block added - OriginalGriff[/edit]