?? form1.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 + -