311Dev 1.0.56.11
dotnet add package 311Dev --version 1.0.56.11
NuGet\Install-Package 311Dev -Version 1.0.56.11
<PackageReference Include="311Dev" Version="1.0.56.11" />
<PackageVersion Include="311Dev" Version="1.0.56.11" />
<PackageReference Include="311Dev" />
paket add 311Dev --version 1.0.56.11
#r "nuget: 311Dev, 1.0.56.11"
#:package 311Dev@1.0.56.11
#addin nuget:?package=311Dev&version=1.0.56.11
#tool nuget:?package=311Dev&version=1.0.56.11
常用控件和工具类
(具体自己用用)
工具操作类
SystemSleepAPI
1.重置系统休眠计时器 ResetSleepTimer
2.获取最后鼠标键盘操作时间 GetLastInput
3.复位最后鼠标键盘操作时间 ResetLastInput
DelayTimer 延时类
1.Restart 重置时间
2.IsOn(Int64 millisecond) 检测是否到达设定时间
3.GetTime 获取耗时
BaseTool
1.延时函数 Delay
2.全屏截图 ScreenshotFull
3.控件截图 ScreenshotControl
4.通过句柄截图-(PrintWindow) ScreenshotControlIntPtr
5.通过句柄截图(增强版)-BitBlt ScreenshotControlIntPtr2
6.图片区域截图 CropBitmap
7.读取datatable的数值 ReadDatatable
8.弹窗显示消息 ShowInfoWindows
9.弹窗显示错误消息 ShowErrorWindows
10.显示弹窗消息,可选择弹窗消息保留时间 ShowTisWindows
11.通过异步方式显示错误提示框,不阻塞程序 ShowErrorForm
12.添加Ping目标ip方法(2025.11.20)
12.1(同步方法)
string ip = "8.8.8.8"; // 目标 IP 或域名
bool isReachable = BaseTool.PingHost(ip, 2000);
Console.WriteLine(isReachable ? $"{ip} 可访问" : $"{ip} 不可访问");
12.2(异步方法、.net4.0不可用)
string ip = "223.5.5.5";
bool isReachable = await BaseTool.PingHostAsync(ip);
Console.WriteLine(isReachable ? $"{ip} 可访问" : $"{ip} 不可访问");
VisionTool_Dev
1.计算两点距离 GetDistance
2.三点计算旋转中心和半径 RotateCenter
3.计算定位点绕旋转中心旋转后坐标 RotateAngle
4.拟合圆(最小二乘)
/// <summary>
/// 拟合圆(最小二乘)
/// </summary>
/// <param name="xList">X点列表</param>
/// <param name="yList">Y点列表</param>
/// <param name="centerX">圆心X</param>
/// <param name="centerY">圆心Y</param>
/// <param name="radius">圆心半径</param>
/// <returns></returns>
public static bool FitCircle(List<double> xList, List<double> yList, out double centerX, out double centerY, out double radius)
IniFile
1.实例化ini类 IniFile
2.读取节点数据 ReadValue
3.写入节点数据 WriteValue
4.获取节点下 所以键名 GetKeys
Logger
1.实例化Log日志类 Logger
2.写日志信息 Log
光源控制器控件
支持光源:
1.HZ-LE200
2.LC-DV2460
3.OPT-DPA1024E
4.MV-LE200
Log显示(绑定到TextBox控件上)
使用步骤:
1.LogShowManagement.Instance.BindTextBoxes(textBox1);
2.LogShowManagement.Instance.ShowMessage("Disconnected from server.");
3.SaveLogEnable =true 开启log记录保存
4.SavePath log保存路径
Log显示(绑定到RichTextBox控件上)
使用步骤:
1.LogShowInfo.Instance.BindTextBoxes(RichTextBox);
2.LogShowInfo.Instance.ShowMessage("Disconnected from server.", MessageType.Info);
3.SaveLogEnable =true 开启log记录保存
4.SavePath log保存路径
5.LogShowInfo.Instance.Max_Chars =1000 设置最大显示字符数
6.LogShowInfo.Instance.Dispose(); 销毁资源
Tool工具-
1.TCPClient TCP客户端方法类(带发送接收超时)
2.TCPClient2 TCP客户端方法类
3.TCPServer TCP服务端方法类
4.TCPClient3 TCP客户端方法类(带断线重连) 获取AreYouOK得到连接状态
// 创建 TCP 客户端实例,连接到 127.0.0.1:8888
var client = new TcpClient2("127.0.0.1", 8888);
// 配置心跳参数(可选,使用默认值时可省略)
client.HeartbeatRequest = "PING"; // 心跳请求消息
client.HeartbeatResponse = "PONG"; // 心跳响应消息
client.HeartbeatInterval = 3000; // 心跳间隔(毫秒)
client.ReconnectInterval = 5000; // 重连间隔(毫秒)
// 注册数据接收回调(不会接收到心跳数据)
client.RegisterDataReceivedCallback(data =>
{
Console.WriteLine($"[业务数据] 收到: {data}");
});
// 监听连接状态变化(包括心跳状态)
client.ConnectionStatusChanged += status =>
{
Console.WriteLine($"[连接状态] {status}");
};
// 监听连接丢失事件
client.ConnectionLost += () =>
{
Console.WriteLine("[警告] 与服务器的连接已断开");
};
// 监听重连成功事件
client.Reconnected += () =>
{
Console.WriteLine("[通知] 已成功重新连接到服务器");
};
// 连接到服务器
bool connected = client.Connect();
if (connected)
{
Console.WriteLine("已成功连接到服务器");
}
else
{
Console.WriteLine("连接失败,将自动尝试重连");
}
// 发送业务数据
client.SendData("Hello, Server!");
// 保持主线程运行,观察连接状态
Console.WriteLine("按任意键退出...");
Console.ReadKey();
// 断开连接
client.Disconnect();
坐标点分类器
1.DevTool.Tools.PointClassification 命名空间
2.PointClassifier pointClassifier = new PointClassifier(double layerHeight = 100, double errorMargin = 10) 层高和层高误差
3.List<List<Point>> pointList = ClassifyAndSortPoints(List<Point> points); 输入坐标点,得到分类结果
加载消息框
在需要显示加载进度的地方调用
LoadingScreen.ShowLoadingScreen(new Size(500, 250), "数据加载中...");更新进度
LoadingScreen.UpdateProgress("正在处理数据...");完成后关闭
LoadingScreen.CloseLoadingScreen();
弹窗确认框
1.DevTool.Tools.ShowMessageForm.ConfirmDialog.Show("确认删除", "确定要删除选中的项目?", showCancel: true,yesText:"删除",noText:"不删除");
// 轮询检查结果
2. while (DevTool.Tools.ShowMessageForm.ConfirmDialog.Result == DevTool.Tools.ShowMessageForm.ConfirmResult.Pending)
{
BaseTool.Delay(100);
}
处理结果
switch (DevTool.Tools.ShowMessageForm.ConfirmDialog.Result)
{
case DevTool.Tools.ShowMessageForm.ConfirmResult.Yes:
MessageBox.Show("执行删除操作");
break;
case DevTool.Tools.ShowMessageForm.ConfirmResult.No:
MessageBox.Show("取消删除");
break;
case DevTool.Tools.ShowMessageForm.ConfirmResult.Cancel:
MessageBox.Show("用户取消");
break;
}
DevTool.Tools.InputSimulator
鼠标键盘模拟
1.获取鼠标坐标
Point point = DevTool.Tools.InputSimulator.GetCurrentPosition();
2.鼠标移动位置
DevTool.Tools.InputSimulator.MoveTo(int x, int y)
在Panel控件上画多行多列的矩形
DevTool.Tools.RectangleDrawer
1.实例化
private RectangleDrawer _drawer;
2.初始化矩形信息
// 初始化矩形框绘制器,创建3行4列的矩形框
_drawer = new RectangleDrawer(drawingPanel, 3, 4, 15);
// 注册矩形框点击事件
_drawer.RectangleClicked += Drawer_RectangleClicked;
// 示例:修改一些矩形框的属性
_drawer.UpdateBorderColor(0, 0, Color.Red);
_drawer.UpdateBorderWidth(0, 0, 3);
_drawer.UpdateBackgroundColor(0, 0, Color.LightPink);
_drawer.UpdateText(0, 0, "这是一个红色边框的矩形框\n有多行文本");
_drawer.UpdateTextSize(0, 0, 12);
_drawer.UpdateBorderColor(1, 2, Color.Blue);
_drawer.UpdateBackgroundColor(1, 2, Color.LightBlue);
_drawer.UpdateText(1, 2, "蓝色边框矩形框");
_drawer.UpdateBackgroundColor(2, 3, Color.LightGreen);
_drawer.UpdateText(2, 3, "这是一个很长的文本,将会自动换行\n以适应矩形框的大小");
3.回调事件处理
//使用
/// <summary>
/// 矩形框点击事件处理
/// </summary>
private void Drawer_RectangleClicked(int row, int col)
{
MessageBox.Show($"你点击了第 {row + 1} 行,第 {col + 1} 列的矩形框!");
// 可以在这里添加自定义处理逻辑
// 例如:根据行列序号执行不同操作
if (row == 0 && col == 0)
{
_drawer.UpdateBackgroundColor(row, col, Color.Yellow);
}
}
ImprovedInputSimulator
鼠标键盘模拟(通过SendInput方式)
private void DelayedTextBox_DelayedTextChanged(object sender, DelayedTextChangedEventArgs e)
{
string triggerType = e.IsEnterKey ? "回车键" : "输入停止2秒";
MessageBox.Show($"检测到{triggerType}!\n输入的文本:{e.Text}", "输入检测");
// 处理文本
if (!string.IsNullOrWhiteSpace(e.Text))
{
// 处理非空文本
}
}
4.增加一种排序方式,从上到下 从右到左 RectangleDrawer2 用法参考1、2、3
public partial class MainForm : Form
{
private RectangleDrawer2 _rectangleDrawer;
public MainForm()
{
InitializeComponent();
// 初始化第一个实例(3行4列)
_rectangleDrawer = new RectangleDrawer2(panel1, 3, 4);
_rectangleDrawer.RectangleClicked += OnRectangleClicked;
}
// 切换为3行3列的按钮点击事件
private void btnSwitchTo3x3_Click(object sender, EventArgs e)
{
// 先释放旧实例
_rectangleDrawer?.Dispose();
// 实例化新的3行3列对象
_rectangleDrawer = new RectangleDrawer2(panel1, 3, 3);
_rectangleDrawer.RectangleClicked += OnRectangleClicked;
}
// 矩形框点击事件处理
private void OnRectangleClicked(int row, int col)
{
// 显示1-based索引(与矩形框上的文本对应)
MessageBox.Show($"点击了 行: {row + 1}, 列: {col + 1}");
}
// 窗体关闭时释放资源
protected override void OnFormClosing(FormClosingEventArgs e)
{
_rectangleDrawer?.Dispose();
base.OnFormClosing(e);
}
// 禁用面板(禁止点击)
rectangleDrawer.SetPanelEnabled(false);
// 启用面板(允许点击)
rectangleDrawer.SetPanelEnabled(true);
}
IpAddressValidator IPV4地址校验(判断字符串是不是格式有效的 2025.8.11)
bool Result = IpAddressValidator.IsValidIpv4Address(string sMsg);
Bitmap图片压缩 DevTool.Tools.ImageCompressor (2025.9.23)
// 示例1:压缩内存中的Bitmap
using (Bitmap originalBitmap = new Bitmap("original.jpg"))
{
// 将图片压缩到最大宽度800,最大高度600,质量70%
using (Bitmap compressedBitmap = ImageCompressor.CompressImage(originalBitmap, 800, 600, 70))
{
compressedBitmap.Save("compressed.jpg", ImageFormat.Jpeg);
}
}
// 示例2:直接压缩图片文件
ImageCompressor.CompressImageFile(
"input.png", // 源文件
"output.jpg", // 目标文件
1024, // 最大宽度
768, // 最大高度
80 // 质量
);
全局消息提示(弹出一个消息窗体,可设置自动消失)
DevTool.Controls.DevUI.Notification.success(this, "Notification Title", "This is the content of the notification. This is the content of the notification. This is the content of the notification.", DevTool.Controls.DevUI.TAlignFrom.Bottom, Font);
DevTool.Controls.DevUI.Notification.error(this, "Notification Title", "This is the content of the notification. This is the content of the notification. This is the content of the notification.", DevTool.Controls.DevUI.TAlignFrom.TR, Font);
DevTool.Controls.DevUI.Notification.warn(this, "Notification Title", "This is the content of the notification. This is the content of the notification. This is the content of the notification.", DevTool.Controls.DevUI.TAlignFrom.TR, Font);
DevTool.Controls.DevUI.Notification.info(this, "Notification Title", "This is the content of the notification. This is the content of the notification. This is the content of the notification.", DevTool.Controls.DevUI.TAlignFrom.TR, Font);
TCPServer 服务端
using System;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;
namespace TcpServerDemo
{
public partial class Form1 : Form
{
private TCPServer _tcpServer;
// 简单示例:保存最后一个发消息的客户端
private TcpClient _currentClient;
public Form1()
{
InitializeComponent();
nudPort.Minimum = 1;
nudPort.Maximum = 65535;
nudPort.Value = 9000;
btnStop.Enabled = false;
btnSend.Enabled = false;
}
private void btnStart_Click(object sender, EventArgs e)
{
try
{
int port = (int)nudPort.Value;
// pingInterval 填 0,暂时关闭原代码中的 Ping 检测
_tcpServer = new TCPServer(port, 0);
_tcpServer.Start(OnMessageReceived);
lblStatus.Text = "运行中,端口:" + port;
btnStart.Enabled = false;
btnStop.Enabled = true;
AppendLog("TCP 服务端已启动");
}
catch (Exception ex)
{
MessageBox.Show(
"启动服务端失败:" + ex.Message,
"错误",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
/// <summary>
/// 接收到客户端消息
/// 注意:此方法在后台线程中执行
/// </summary>
private void OnMessageReceived(TcpClient client, string message)
{
_currentClient = client;
string clientAddress = "未知客户端";
try
{
if (client.Client.RemoteEndPoint != null)
{
clientAddress = client.Client.RemoteEndPoint.ToString();
}
}
catch
{
// 客户端可能已经断开
}
AppendLog(
string.Format("[{0:HH:mm:ss}] [{1}] {2}",
DateTime.Now,
clientAddress,
message));
// 收到消息后自动回复,按需要保留或删除
// _tcpServer.SendMessage(client, "服务端已收到:" + message);
}
/// <summary>
/// 线程安全地更新日志框
/// </summary>
private void AppendLog(string message)
{
if (IsDisposed || Disposing)
return;
if (txtReceive.InvokeRequired)
{
txtReceive.BeginInvoke(new Action<string>(AppendLog), message);
return;
}
txtReceive.AppendText(message + Environment.NewLine);
txtReceive.SelectionStart = txtReceive.TextLength;
txtReceive.ScrollToCaret();
btnSend.Enabled = _currentClient != null &&
_currentClient.Connected;
}
private void btnSend_Click(object sender, EventArgs e)
{
if (_tcpServer == null)
{
MessageBox.Show("TCP 服务端尚未启动。");
return;
}
if (_currentClient == null || !_currentClient.Connected)
{
MessageBox.Show("当前没有可用的客户端连接。");
return;
}
string message = txtSend.Text;
if (string.IsNullOrWhiteSpace(message))
{
MessageBox.Show("请输入要发送的内容。");
return;
}
try
{
_tcpServer.SendMessage(_currentClient, message);
AppendLog("[服务端发送] " + message);
}
catch (Exception ex)
{
AppendLog("[发送失败] " + ex.Message);
}
}
private void btnStop_Click(object sender, EventArgs e)
{
StopServer();
}
private void StopServer()
{
try
{
if (_tcpServer != null)
{
_tcpServer.Stop();
_tcpServer = null;
}
}
catch (Exception ex)
{
AppendLog("[停止异常] " + ex.Message);
}
finally
{
_currentClient = null;
lblStatus.Text = "已停止";
btnStart.Enabled = true;
btnStop.Enabled = false;
btnSend.Enabled = false;
AppendLog("TCP 服务端已停止");
}
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
StopServer();
base.OnFormClosing(e);
}
}
}
最后更新日期:2026.8.25 By Justin
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.0.56.11 | 87 | 8/25/2026 | |
| 1.0.56.10 | 109 | 8/13/2026 | |
| 1.0.56.9 | 89 | 8/7/2026 | |
| 1.0.56.8 | 94 | 8/7/2026 | |
| 1.0.56.7 | 165 | 1/28/2026 | |
| 1.0.56.6 | 447 | 11/20/2025 | |
| 1.0.56.5 | 227 | 10/21/2025 | |
| 1.0.56.4 | 301 | 10/21/2025 | |
| 1.0.56.3 | 225 | 10/13/2025 | |
| 1.0.56.2 | 250 | 10/4/2025 | |
| 1.0.55.19 | 217 | 9/29/2025 | |
| 1.0.55.18 | 215 | 9/26/2025 | |
| 1.0.55.17 | 232 | 9/23/2025 | |
| 1.0.55.16 | 316 | 9/15/2025 | |
| 1.0.55.12 | 312 | 9/15/2025 | |
| 1.0.55.11 | 175 | 9/12/2025 |