当前位置:编程学习 > C#/ASP.NET >>

求 通过timer组件实现 下雨效果(最好有c#源代码),谢谢。

   如题,务必帮帮小妹啊。 --------------------编程问答-------------------- 你先试试,不明白再问:

// RainDrops.cs
// compile with:   csc /t:winexe RainDrops.cs
using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
    Bitmap rainDrops;
    Timer timer = new Timer();
    int top = 0;

    public Form1()
    {
        this.Size = new Size(300, 300);
        Rectangle rect = this.ClientRectangle;

        rainDrops = new Bitmap(rect.Width, rect.Height * 2);
        using (Graphics g = Graphics.FromImage(rainDrops))
        {
            g.Clear(Color.LightBlue);

            Random random = new Random();
            for (int i = 0; i < 1000; i++)
            {
                int x = random.Next() % rect.Width;
                int y = random.Next() % rect.Height;
                int dot = random.Next() % 5;

                g.FillEllipse(Brushes.White, x, y, dot, dot);
                g.FillEllipse(Brushes.White, x, y+rect.Height, dot, dot);
            }
        }
        timer.Interval = 200;
        timer.Enabled = true;
        timer.Tick += delegate { Invalidate(); };

    }

    protected override void OnPaint(PaintEventArgs e)
    {
        int height = this.ClientRectangle.Height;
        top += 10;
        if (top > height) top = 0;
        e.Graphics.DrawImageUnscaled(rainDrops, 0, top - height);
    }

    protected override void OnPaintBackground(PaintEventArgs e)
    {
    }

    static void Main()
    {
        Application.Run(new Form1());
    }
}
--------------------编程问答-------------------- 这好像是下雪吧!!!! --------------------编程问答-------------------- 那就换个图片 --------------------编程问答-------------------- 很好很强大 --------------------编程问答-------------------- 都下冰雹咯!!! --------------------编程问答-------------------- 女的就喜欢搞这个 --------------------编程问答-------------------- 花里胡哨的东东~~~~~~~~~~~~~~ --------------------编程问答-------------------- 呵呵,想象就很玩。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,