日期:2014-05-18  浏览次数:20786 次

一个圣诞祝福的经典小程序大家看能不能用C#技术实现类似的效果
http://download.csdn.net/detail/hjleaven/3979202

------解决方案--------------------
不好意思,回复晚了。

①你需要将控制雪花所有操作生成一个类(包括雪花的坐标,移动速度,图片等等)
②你在桌面上生成的东西肯定会有刷新的,如果你不想这样,你可以让他在你的Form下运行。

我给你配上一个源码,你参考一下吧,和你要实现的功能是一样的~~
C# code

private void timer_Tick(object sender, EventArgs e)
        {
            Tick++;

            if (Tick % 10 == 0)
            {
                SnowFlake s = new SnowFlake();
                Random rd = new Random();
                s.X = rand.Next(-20, this.Width + 20);
                s.Y = 0f;
                s.XVelocity = (float)(rand.NextDouble() - 0.5f) * 2f;
                s.YVelocity = (float)(rand.NextDouble() * 3) + 1f;
                s.Rotation = rand.Next(0, 359);
                s.RotVelocity = rand.Next(-3, 3) * 2;
                s.image = Image.FromFile(@"Resources\" + rd.Next(1, 4) + ".gif");
                if (s.RotVelocity == 0)
                {
                    s.RotVelocity = 3;
                }
                s.Scale = (float)(rand.NextDouble() / 2) + 0.75f;
                SnowFlakes.Add(s);
            }

            Graphics g = Graphics.FromImage(screenImage);
            g.Clear(Color.Transparent);
            g.SmoothingMode = SmoothingMode.HighSpeed;

            for (int i = 0; i < SnowFlakes.Count; i++)
            {
                SnowFlake s1 = SnowFlakes[i];
                s1.X += s1.XVelocity;
                s1.Y += s1.YVelocity;
                s1.Rotation += s1.RotVelocity;
                s1.XVelocity += ((float)rand.NextDouble() - 0.5f) * 0.7f;
                s1.XVelocity = Math.Max(s1.XVelocity, -2f);
                s1.XVelocity = Math.Min(s1.XVelocity, +2f);

                if (s1.Y > this.Height)
                {
                    SnowFlakes.RemoveAt(i);
                }
                else
                {

                    g.ResetTransform();
                    g.TranslateTransform(-16, -16, MatrixOrder.Append); //pan
                    g.ScaleTransform(s1.Scale, s1.Scale, MatrixOrder.Append); //scale
                    g.RotateTransform(s1.Rotation, MatrixOrder.Append); //rotate
                    g.TranslateTransform(s1.X, s1.Y, MatrixOrder.Append); //pan
                    g.DrawImage(s1.image, 0, 0); //draw
                }
            }
            g.Dispose();
            SetBackground(screenImage);
        }