⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 这是即时桌面显示任务的代码!用.net编写
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using Microsoft.Win32;

namespace ActiveDektop
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.NotifyIcon notifyIcon1;
		private System.Windows.Forms.ContextMenu contextMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.ListBox lbxTasks;
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.label1 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.lbxTasks = new System.Windows.Forms.ListBox();
			this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 8);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "新任务";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(64, 8);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(360, 21);
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(432, 8);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "添加";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(512, 8);
			this.button2.Name = "button2";
			this.button2.TabIndex = 3;
			this.button2.Text = "删除";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// lbxTasks
			// 
			this.lbxTasks.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(0)));
			this.lbxTasks.ItemHeight = 12;
			this.lbxTasks.Location = new System.Drawing.Point(8, 40);
			this.lbxTasks.Name = "lbxTasks";
			this.lbxTasks.Size = new System.Drawing.Size(584, 352);
			this.lbxTasks.TabIndex = 4;
			// 
			// notifyIcon1
			// 
			this.notifyIcon1.ContextMenu = this.contextMenu1;
			this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
			this.notifyIcon1.Text = "我的任务";
			this.notifyIcon1.Visible = true;
			// 
			// contextMenu1
			// 
			this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						 this.menuItem1,
																						 this.menuItem2,
																						 this.menuItem3});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "添加任务";
			this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.Text = "-";
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 2;
			this.menuItem3.Text = "退出";
			this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
			// 
			// Form1
			// 
			this.AcceptButton = this.button1;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(600, 429);
			this.Controls.Add(this.lbxTasks);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label1);
			this.Name = "Form1";
			this.Text = "我的任务";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main(string[] args) 
		{
			if (args.Length == 1) {
				arg = args[0];
			}
			Form1 frm = new Form1();
			
			Application.Run(frm);
		}

		private static string arg = "";

		[DllImport("User32.dll")]
		public static extern bool SystemParametersInfoA(
			long uAction,       
			long uParam,    
			object lpvParam,
			long fuWinIni   
			);


		private void button1_Click(object sender, System.EventArgs e) {
			// 保存内容
			this.lbxTasks.Items.Add("● " + this.textBox1.Text);
			// 画
			DrawNow();
			// 保存
			SaveNow();

			this.textBox1.Text = "";
		}

		public void SaveNow() {
			string s = "";
			foreach (object item in this.lbxTasks.Items) s += item.ToString() + "\n";
			if (s.Length > 0) s = s.Substring(0, s.Length - 1);
			RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\UUT\ActiveDesktop");
			key.SetValue("Tasks", s);
		}

		public void DrawNow() {
			string fileName = @"c:\windows\ActiveDesktop.bmp";
			// 生成图片
			Rectangle rec = Screen.PrimaryScreen.Bounds;
			Image img = new Bitmap(rec.Width, rec.Height);
			Graphics g = Graphics.FromImage(img);
			g.FillRectangle(new SolidBrush(Color.FromArgb(58, 110, 165)), 0, 0, img.Width - 1, img.Height - 1);
			
			int left = img.Width - 300, top = 10;
			g.FillRectangle(Brushes.DarkBlue, left, top, 290, 19);
			g.DrawString("我的任务", this.Font, Brushes.White, left + 5, top + 3);
			
			g.FillRectangle(new SolidBrush(Color.FromArgb(116, 153, 191)), left, top + 19, 290, 400);
			string s;
			for (int i = 0; i < this.lbxTasks.Items.Count; i++) {
				s = this.lbxTasks.Items[i].ToString();
				g.DrawString(s, new Font("宋体", 10.5f), Brushes.White, left + 5, top + (i + 1) * 19 + 4);
			}

			SizeF size = g.MeasureString("My i-VTEC", new Font("Times New Roman", 70f));
			g.DrawString("My i-VTEC", new Font("Times New Roman", 70f), Brushes.LightBlue, 
				(rec.Width - size.Width)/2, (rec.Height - size.Height)/2);
			g.DrawString("UUT", new Font("Eras Bold ITC", 36f, FontStyle.Bold), new SolidBrush(Color.FromArgb(128, 128, 0)), 
				(rec.Width - size.Width)/2 + 3, (rec.Height - size.Height)/2 - 28);
			g.DrawString("ech", new Font("Eras Bold ITC", 36f, FontStyle.Bold), new SolidBrush(Color.FromArgb(70, 70, 0)), 
				(rec.Width - size.Width)/2 + 106, (rec.Height - size.Height)/2 - 28);
			g.DrawString("www.ucargo.net", new Font("Verdana", 18f, FontStyle.Bold), new SolidBrush(Color.Yellow), 
				(rec.Width - size.Width)/2 + 245, (rec.Height - size.Height)/2 + 80);

			img.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);

			RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\Desktop\General");
			key.SetValue("BackupWallpaper", fileName);
			key.SetValue("Wallpaper", fileName);
			key = Registry.CurrentUser.CreateSubKey(@"Control Panel\Desktop");
			key.SetValue("Wallpaper", fileName);

			// 刷新
			System.Diagnostics.Debug.WriteLine(SystemParametersInfoA(20, 0, null, 2));
		}

		private void menuItem1_Click(object sender, System.EventArgs e) {
			this.Visible = true;
			this.WindowState = FormWindowState.Normal;
		}

		private void menuItem3_Click(object sender, System.EventArgs e) {
			RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\Desktop\General");
			key.SetValue("BackupWallpaper", "");
			key.SetValue("Wallpaper", "");
			key = Registry.CurrentUser.CreateSubKey(@"Control Panel\Desktop");
			key.SetValue("Wallpaper", "");

			// 刷新
			System.Diagnostics.Debug.WriteLine(SystemParametersInfoA(20, 0, null, 2));
			Application.Exit();
		}

		private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
			if (this.Visible) {
				e.Cancel = true;
				this.WindowState = FormWindowState.Minimized;
				this.Visible = false;
			}
		}

		private void Form1_Load(object sender, System.EventArgs e) {
			// 读取值
			string s = "";
			RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\UUT\ActiveDesktop");
			if (key.GetValue("Tasks") != null) {
				s = (string)key.GetValue("Tasks");
				string[] ss = s.Split(new char[] { '\n' });
				this.lbxTasks.Items.Clear();
				this.lbxTasks.Items.AddRange(ss);
			}

			DrawNow();
		}

		private void button2_Click(object sender, System.EventArgs e) {
			if (this.lbxTasks.SelectedIndex > -1) {
				this.lbxTasks.Items.RemoveAt(this.lbxTasks.SelectedIndex);
				DrawNow();
				SaveNow();
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -