首页 桌面下雪程序

桌面下雪程序

举报
开通vip

桌面下雪程序桌面下雪程序 完整版本,下雪了 C# code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Reflectio...

桌面下雪程序
桌面下雪程序 完整版本,下雪了 C# code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Reflection; using System.Threading; namespace WindowsApplication30 { public partial class frmDesktopSnow : Form { /// /// 下雪啦 /// [DllImport("User32.dll ", EntryPoint = "FindWindow")] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("User32.dll ")] static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childe, string strclass, string strname); List SnowPoints = new List(); List SnowRate = new List(); Bitmap Bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); IntPtr DesktopHandle = IntPtr.Zero; #region public frmDesktopSnow() // 构造函数 /// /// 构造函数 /// public frmDesktopSnow() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; BtnStart.Size = new Size(100, 70); BtnClose.Size = new Size(100, 70); BtnStart.Location = new Point(0, 0); BtnClose.Location = new Point(101, 0); BtnStart.Text = "点一下吧"; BtnClose.Text = "关闭"; this.Size = new Size(BtnClose.Right, BtnClose.Bottom); this.Opacity = 0.8; } #endregion #region void SnowTimer_Tick(object sender, EventArgs e) // 下雪计时器事件 /// /// 下雪计时器事件 /// /// 计时器本身 /// 计时器参数 void SnowTimer_Tick(object sender, EventArgs e) { Graphics DesktopGraphics = Graphics.FromHwnd(DesktopHandle); String Text = "圣诞快到了,希望大家身体健康~"; if (Convert.ToInt32(SnowTimer.Tag) == 0) DesktopGraphics.DrawString(Text, new Font("宋体", 10), new SolidBrush(Color.Red), new PointF(Screen.PrimaryScreen.Bounds.Width / 2 - 200, Screen.PrimaryScreen.Bounds.Height / 2)); else DesktopGraphics.DrawString(Text, new Font("宋体", 10), new SolidBrush(Color.Green), new PointF(Screen.PrimaryScreen.Bounds.Width / 2 - 200, Screen.PrimaryScreen.Bounds.Height / 2)); SnowTimer.Tag = 1 - Convert.ToInt32(SnowTimer.Tag); for (int i = 0; i < SnowPoints.Count; i++) { DesktopGraphics.DrawImage(Bmp, SnowPoints[i].X, SnowPoints[i].Y, new Rectangle(SnowPoints[i], PbSnow.Size), GraphicsUnit.Pixel); SnowPoints[i] = new Point(SnowPoints[i].X, SnowPoints[i].Y + SnowRate[i]); if (SnowPoints[i].Y > Screen.PrimaryScreen.Bounds.Bottom) SnowPoints[i] = new Point(SnowPoints[i].X, 0); DesktopGraphics.DrawImage(PbSnow.Image, SnowPoints[i]); // PbSnow.Image 小雪花图片 } DesktopGraphics.Dispose(); } #endregion #region void BtnStart_Click(object sender, EventArgs e) // 下雪 /// /// 开始下雪 /// /// 按钮本身 /// 按钮 void BtnStart_Click(object sender, EventArgs e) { SnowPoints.Clear(); Random R = new Random(); for (int i = 0; i < 50; i++) { SnowPoints.Add(new Point(R.Next(Screen.PrimaryScreen.Bounds.Width), R.Next(Screen.PrimaryScreen.Bounds.Height))); SnowRate.Add(R.Next(10)); } ShowDesktop(); this.WindowState = FormWindowState.Minimized; Thread.Sleep(500); // 等待桌面完全显示 Graphics G = Graphics.FromImage(Bmp); G.CopyFromScreen(new Point(0, 0), new Point(Screen.PrimaryScreen.Bounds.Left, Screen.PrimaryScreen.Bounds.Top), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)); G.Dispose(); this.WindowState = FormWindowState.Normal; IntPtr P = FindWindow("Progman", "Program Manager"); P = FindWindowEx(P, IntPtr.Zero, "SHELLDLL_DefView", null); DesktopHandle = FindWindowEx(P, IntPtr.Zero, "SysListView32", null); SnowTimer.Interval = 1; SnowTimer.Enabled = true; // 开始下雪 } #endregion #region void BtnClose_Click(object sender, EventArgs e) // 关闭 /// /// 关闭 /// /// 窗口本身 /// 窗口参数 void BtnClose_Click(object sender, EventArgs e) { ShowDesktop(); Close(); } #endregion #region static void ShowDesktop() // 显示桌面 /// /// 显示桌面 /// static void ShowDesktop() { Type OleType = Type.GetTypeFromProgID("Shell.Application"); object OleObject = System.Activator.CreateInstance(OleType); OleType.InvokeMember("ToggleDesktop", BindingFlags.InvokeMethod, null, OleObject, null); } #endregion } } 小雪花图片用网上有的小雪花矢量图jpg或bmp用photoshop把背景颜色的区域删掉镂空成透明保存成GIF然后导入PbSnow PictureBox控件
本文档为【桌面下雪程序】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_591137
暂无简介~
格式:doc
大小:22KB
软件:Word
页数:7
分类:生活休闲
上传时间:2018-01-06
浏览量:95