Lete乐特自制实用工具(C# - .NET Framework4.5)
由于上次使用Java编写的实用工具https://lete114.github.io/article/986f7d9c.html
Java写窗体程序的优缺点 优点:
可跨平台 缺点:
Java程序依赖JVM(Java虚拟机) 由于JVM是存储在jre下的(而Java程序又依赖JVM(Java虚拟机))jre占用内存高达200MB C#写窗体程序的优缺点 由于Java程序不便于携带,这次我使用C#编写
优点:
体积小(小于1MB) 便于携带 便于编写(随意拖动按钮图标等) 缺点:
C#依赖 .NET Framework (这个不要紧,大多数电脑都会装有 .NET Framework,玩游戏的应该需要装游戏运行库,运行库里就包含有 .NET Framework) FormMain.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Runtime.InteropServices;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace Delete { public partial class FormMain : Form { public FormMain ( ) { InitializeComponent(); } [DllImport("user32.dll" ) ] private static extern IntPtr GetDC (IntPtr hwnd ) ; [DllImport("gdi32.dll" ) ] private static extern int GetPixel (IntPtr hdc, Point p ) ; private void lete_Click (object sender, EventArgs e ) { System.Diagnostics.Process.Start("http://lete114.github.io/" ); } private void LeteTools_Load (object sender, EventArgs e ) { this .tm.Enabled = true ; this .tm.Interval = 1 ; } private void tm_Tick (object sender, EventArgs e ) { Timer tim = new Timer(); tim.Interval = 1 ; tim.Tick += delegate { Point p = new Point(MousePosition.X, MousePosition.Y); IntPtr hdc = GetDC(new IntPtr(0 )); int c = GetPixel(hdc, p); int r = (c & 0xFF ); int g = (c & 0xFF00 ) / 256 ; int b = (c & 0xFF0000 ) / 65536 ; lblR255.Text = r.ToString(); lblG255.Text = g.ToString(); lblB255.Text = b.ToString(); FormMain lt = new FormMain(); lblVHEX.Text = lt.convertRGBToHex(r, g, b); lblVX.Text = Control.MousePosition.X.ToString(); lblVY.Text = Control.MousePosition.Y.ToString(); }; tim.Start(); } public String convertRGBToHex (int r, int g, int b ) { String rFString, rSString, gFString, gSString, bFString, bSString, result; int red, green, blue; int rred, rgreen, rblue; red = r / 16 ; rred = r % 16 ; if (red == 10 ) rFString = "A" ; else if (red == 11 ) rFString = "B" ; else if (red == 12 ) rFString = "C" ; else if (red == 13 ) rFString = "D" ; else if (red == 14 ) rFString = "E" ; else if (red == 15 ) rFString = "F" ; else rFString = red.ToString(); if (rred == 10 ) rSString = "A" ; else if (rred == 11 ) rSString = "B" ; else if (rred == 12 ) rSString = "C" ; else if (rred == 13 ) rSString = "D" ; else if (rred == 14 ) rSString = "E" ; else if (rred == 15 ) rSString = "F" ; else rSString = rred.ToString(); rFString = rFString + rSString; green = g / 16 ; rgreen = g % 16 ; if (green == 10 ) gFString = "A" ; else if (green == 11 ) gFString = "B" ; else if (green == 12 ) gFString = "C" ; else if (green == 13 ) gFString = "D" ; else if (green == 14 ) gFString = "E" ; else if (green == 15 ) gFString = "F" ; else gFString = green.ToString(); if (rgreen == 10 ) gSString = "A" ; else if (rgreen == 11 ) gSString = "B" ; else if (rgreen == 12 ) gSString = "C" ; else if (rgreen == 13 ) gSString = "D" ; else if (rgreen == 14 ) gSString = "E" ; else if (rgreen == 15 ) gSString = "F" ; else gSString = rgreen.ToString(); gFString = gFString + gSString; blue = b / 16 ; rblue = b % 16 ; if (blue == 10 ) bFString = "A" ; else if (blue == 11 ) bFString = "B" ; else if (blue == 12 ) bFString = "C" ; else if (blue == 13 ) bFString = "D" ; else if (blue == 14 ) bFString = "E" ; else if (blue == 15 ) bFString = "F" ; else bFString = blue.ToString(); if (rblue == 10 ) bSString = "A" ; else if (rblue == 11 ) bSString = "B" ; else if (rblue == 12 ) bSString = "C" ; else if (rblue == 13 ) bSString = "D" ; else if (rblue == 14 ) bSString = "E" ; else if (rblue == 15 ) bSString = "F" ; else bSString = rblue.ToString(); bFString = bFString + bSString; result = "#" + rFString + gFString + bFString; return result; } private void Zhu_Click (object sender, EventArgs e ) { Delete m = new Delete(); m.Show(); } } }
Delete.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace Delete { public partial class Delete : Form { public Delete ( ) { InitializeComponent(); } private void btnDelete_Click (object sender, EventArgs e ) { string str = txtPath.Text; str.Replace("\\" , "/" ); if (str.Equals("" )) { MessageBox.Show("路径不能为空!" , "提示" ); } else if (str.Equals("Q:\\" ) || str.Equals("W:\\" ) || str.Equals("E:\\" ) || str.Equals("R:\\" ) || str.Equals("T:\\" ) || str.Equals("Y:\\" ) || str.Equals("U:\\" ) || str.Equals("I:\\" ) || str.Equals("O:\\" ) || str.Equals("P:\\" )|| str.Equals("A:\\" ) || str.Equals("S:\\" ) || str.Equals("D:\\" ) || str.Equals("G:\\" ) || str.Equals("H:\\" )|| str.Equals("J:\\" ) || str.Equals("K:\\" ) || str.Equals("L:\\" ) || str.Equals("Z:\\" ) || str.Equals("X:\\" )|| str.Equals("C:\\" ) || str.Equals("C:\\" ) || str.Equals("V:\\" ) || str.Equals("B:\\" ) || str.Equals("N:\\" )|| str.Equals("M:\\" )) { MessageBox.Show("路径不能为盘符!" , "提示" ); } else { getPath(str); } } private void Main_Load (object sender, EventArgs e ) { } private void btnLL_Click (object sender, EventArgs e ) { FolderBrowserDialog f = new FolderBrowserDialog(); if (f.ShowDialog() == DialogResult.OK) { String DirPath = f.SelectedPath; this .txtPath.Text = DirPath; } } static List <string > list = new List<string >(); public List<string > getPath (string path ) { DirectoryInfo dir = new DirectoryInfo(path); FileInfo[] fil = dir.GetFiles(); DirectoryInfo[] dii = dir.GetDirectories(); foreach (FileInfo f in fil) { list.Add(f.FullName); } foreach (DirectoryInfo d in dii) { getPath(d.FullName); list.Add(d.FullName); } DirectoryInfo[] subdirs = dir.GetDirectories("*.*" , SearchOption.AllDirectories); foreach (DirectoryInfo subdir in subdirs) { FileSystemInfo[] subFiles = subdir.GetFileSystemInfos(); if (subFiles.Count() == 0 ) { subdir.Delete(); } } return list; } } }
Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using System.Windows.Forms;namespace Delete { static class Program { [STAThread ] static void Main ( ) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false ); Application.Run(new FormMain()); } } }
下载地址 这里顺便推荐个云盘曲奇云盘https://quqi.com 用了有几个月了还不错 同样和百度云一样送2T空间,晚了可能就没有了,关键是不限速
曲奇云盘:https://quqi.gblhgk.com/s/47889/mAxdzF3Auy0rAN0t
Github:https://github.com/lete114/C.Tools
Gitee:https://github.com/lete114/C.Tools