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
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;//timer控件的执行频率
}
//计时器
private void tm_Tick(object sender, EventArgs e)
{
// 计时器
Timer tim = new Timer();
tim.Interval = 1;
tim.Tick += delegate
{
//获取RGB鼠标当前位置颜色
Point p = new Point(MousePosition.X, MousePosition.Y);//取置顶点坐标
IntPtr hdc = GetDC(new IntPtr(0));//取到设备场景(0就是全屏的设备场景)
int c = GetPixel(hdc, p);//取指定点颜色
int r = (c & 0xFF);//转换R
int g = (c & 0xFF00) / 256;//转换G
int b = (c & 0xFF0000) / 65536;//转换B
//RGB.BackColor = Color.FromArgb(r, g, b);
lblR255.Text = r.ToString();
lblG255.Text = g.ToString();
lblB255.Text