ITPUB??ì3
ITPUB论坛 » ASP.NET » 求 通过timer组件实现 下雨效果(最好有c#源代码),谢谢。


标题: 求 通过timer组件实现 下雨效果(最好有c#源代码),谢谢。
离线 cayman811
高级会员



精华贴数 3
个人空间 0
技术积分 7101 (170)
社区积分 6 (13854)
注册日期 2006-8-9
论坛徽章:5
开发板块每日发贴之星开发板块每日发贴之星ITPUB新首页上线纪念徽章   
      

发表于 2008-5-13 15:37 
求 通过timer组件实现 下雨效果(最好有c#源代码),谢谢。

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


只看该作者    顶部
离线 hanfeishu
中级会员



精华贴数 0
个人空间 0
技术积分 2222 (672)
社区积分 0 (1281163)
注册日期 2007-2-28
论坛徽章:19
开发板块每日发贴之星生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠
生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠

发表于 2008-5-13 15:37 
你先试试,不明白再问:

C# code
// 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());
    }
}


只看该作者    顶部
离线 cyntha80
中级会员



精华贴数 1
个人空间 0
技术积分 2713 (537)
社区积分 2 (29350)
注册日期 2007-2-8
论坛徽章:20
开发板块每日发贴之星生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠
生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠生肖徽章2007版:鼠

发表于 2008-5-13 15:38 
这好像是下雪吧!!!!


只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问