
C#
工地搬砖人
自信来源于实力,实力来源于勤奋。
展开
-
C# 连接basler相机
using Basler.Pylon;using System;using System.Drawing;using System.Drawing.Imaging;namespace basler相机连接{ class baslerCamcs { //相机连接的个数 public int CameraNumber = CameraF...原创 2019-10-07 20:50:52 · 6258 阅读 · 9 评论 -
C# 连接大华工业相机
需要导入这两个动态链接库using HalconDotNet;using System;using System.Collections.Generic;using System.Diagnostics;using System.Drawing;using System.Drawing.Imaging;using System.Linq;using System.Thread...原创 2020-01-07 10:34:47 · 6961 阅读 · 4 评论 -
winform 继承窗体卡顿解决
get { const int CS_NOCLOSE = 0x200; CreateParams cp = base.CreateParams; cp.ClassStyle = cp.ClassStyle | CS_NOCLOSE; if (!DesignMode) { cp.ExS...原创 2021-08-23 11:59:58 · 477 阅读 · 0 评论 -
C# CRC校验
#region**CRC Computation** public void GetCRC(byte[] message, ref byte[] CRC) { //Function expects a modbus message of any length as well as a 2 byte CRC array in which to //return the CRC values: usho.原创 2021-01-19 15:02:37 · 868 阅读 · 0 评论 -
C# 压缩解压Zip文件
//添加引用ICSharpCode.SharpZipLib.dll/// <summary> /// Zip 压缩文件 /// </summary> public class Zip { public Zip() { } #region 加压方法 /// <summary> /// 功能:压缩文件(暂时只压缩文件夹下一级目录中的文件,.原创 2020-12-24 02:04:12 · 2241 阅读 · 0 评论 -
C# 写日志
public static void WriteLog(string msg) { string filePath = AppDomain.CurrentDomain.BaseDirectory + "Log"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } ..原创 2020-11-27 17:22:00 · 813 阅读 · 0 评论 -
C# 二维数组
//定义string类型的数组 string[,,] Account = new string[100,4,4]; //统计数组长度 int AccountCount = 0; for (int i = 0; i < 100; i++) { for (int j = 0; j < 4; j++) ..原创 2020-11-27 10:07:28 · 1779 阅读 · 0 评论 -
C# ini读取一个节点下所有键值
[DllImport("kernel32.dll")]private static extern int GetPrivateProfileSection(string lpAppName, byte[] lpszReturnBuffer, int nSize, string lpFileName);public static Dictionary<string, string> GetKeys(string iniFile, string category){ byte[].原创 2020-11-25 16:36:41 · 3018 阅读 · 1 评论 -
C# flowLayoutPanel1里动态添加控件
//添加控件Button button = new Button();button.ImageAlign = System.Drawing.ContentAlignment.TopCenter;button.Location = new System.Drawing.Point(3, 0);button.Name = "button1";button.Size = new System.Drawing.Size(118, 117);button.TabIndex = 0;button.Tex.原创 2020-11-25 16:32:45 · 3618 阅读 · 0 评论 -
C# 遍历ToolStripMenuItem
ToolStripMenuItem tool = (ToolStripMenuItem)sender; for (int i = 0; i < this.初始状态ToolStripMenuItem.DropDownItems.Count; i++) { ToolStripMenuItem cb = this.初始状态ToolStripMenuItem.DropDownItems[i] as ToolStripMenuIt.原创 2020-11-04 14:30:42 · 1917 阅读 · 0 评论 -
winform 防止遮挡任务栏
//遮挡任务栏全屏this.MaximumSize = new Size(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height); //防止遮挡任务栏//this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width,Screen.PrimaryScreen.WorkingArea.Height);...原创 2020-11-03 10:12:34 · 379 阅读 · 0 评论 -
C# 无损压缩图片
/// <summary>/// 无损压缩图片/// </summary>/// <param name="sFile">原图片地址</param>/// <param name="dFile">压缩后保存图片地址</param>/// <param name="flag">压缩质量(数字越小压缩率越高)1-100</param>/// <param name="size">压缩后图片的最原创 2020-11-04 14:33:05 · 505 阅读 · 0 评论 -
C# 读写dat
private static void ReadDat() { //使用“另存为”对话框中输入的文件名实例化FileStream对象 FileStream myStream = new FileStream("license.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite); //使用FileStream对象实例化BinaryWriter二进制..原创 2020-08-04 18:11:07 · 2542 阅读 · 0 评论 -
C# 三菱PLC FX5U 通信
需要引用这三个库:实例: //添加PLC控件 axActUtlType = new AxActUtlType(); Controls.Add(this.axActUtlType); //打开PLC string s = MitsubishiHelper.Open(ref axActUtlType, 1);/// <summary> //.原创 2020-08-04 18:01:36 · 3449 阅读 · 6 评论 -
C# 获取指定文件夹下所有的文件
DirectoryInfo dirs = new DirectoryInfo(System.Environment.CurrentDirectory + @"\11\"); FileInfo[] file = dirs.GetFiles();//获得目录下文件对 //循环文件 for (int j = 0; j < file.Count(); j++) { ..原创 2020-08-04 17:53:00 · 531 阅读 · 0 评论 -
C# 图片透明
/// <summary> /// 处理图片透明操作 /// </summary> /// <param name="srcImage">原始图片</param> /// <param name="opacity">透明度(0.0---1.0)</param> /// <returns></returns> pri..原创 2020-11-04 14:33:35 · 562 阅读 · 0 评论 -
C# halcon hobject 快速转Bitmap
Bitmap Honject2Bitmap(HObject hObject) { //获取图像尺寸 HOperatorSet.GetImageSize(hObject, out HTuple width0, out HTuple height0); HOperatorSet.GetImageSize(hObject, out width0, out height0); //创建交错格式图像..原创 2020-07-13 23:43:30 · 2073 阅读 · 0 评论 -
C# LZW算法压缩tiff图像
OpenFileDialog opndlg = new OpenFileDialog(); opndlg.Filter = "所有图像文件|*.bmp;*.pcx;*.png;*.jpg;*.gif;*.raw;*.tiff;*.tif"; opndlg.Title = "打开图像文件"; if (opndlg.ShowDialog() == DialogResult.OK) { ..原创 2020-07-02 20:04:20 · 1876 阅读 · 0 评论 -
C# 固高点位运动
#region 点位运动 /// <summary> /// 点位运动 /// </summary> /// <param name="axis">轴号</param> /// <param name="acc">加速度 </param> /// <param name="dec">减速度</param> ..原创 2020-07-02 03:00:04 · 1462 阅读 · 0 评论 -
C# 固高Jog运动
#region JOG运动 /// <summary> /// JOG运动 /// </summary> /// <param name="axis">轴号</param> /// <param name="acc">加速度</param> /// <param name="dec">减速度</param>...原创 2020-07-02 02:59:17 · 1063 阅读 · 0 评论 -
C#与halcon联合编程 HObject转Bitmap
// halcon rgb变量转C# bitmap变量 public static Bitmap HObject2Bitmap3(HObject ho) { Bitmap bimp = null; HTuple hred, hgreen, hblue, type, width, height; HOperatorSet.GetImagePointer3(ho, ou...原创 2020-05-18 16:43:47 · 853 阅读 · 0 评论 -
C#与Halcon联合编程 HObject转OpenCVSharp Mat
public static Mat HImageToMat(HObject hobj){ try { Mat pImage; HTuple htChannels; HTuple cType = null; HTuple width, height; width = height = 0; htChannels = null; HOperatorSet.CountChannels(hobj, out htChannels); if (htChannels.Lengt.原创 2020-05-18 14:33:04 · 2103 阅读 · 2 评论 -
C# TCP/iP通信
private delegate void UsetEventHandler(); private static Socket _serveSocket = null; private static Thread _listthread = null; private static Socket _socket=null; private static Thread _receiveThread = null; #region.原创 2020-05-18 00:26:00 · 1565 阅读 · 0 评论 -
C# OpenFileDialog控件使用
使用C#代码操作:OpenFileDialog openFileDialog=new OpenFileDialog(); openFileDialog.InitialDirectory="c:\\";//注意这里写路径时要用c:\\而不是c:\ openFileDialog.Filter="文本文件|*.*|C#文件|*.cs|所有文件|*.*"; openFile...原创 2020-04-24 12:26:57 · 841 阅读 · 0 评论 -
Halcon 报错“HALCON error #1201: Wrong type of control parameter 1 in operator set_comprise ”
1、现在你的halcon实际用的另一个版本,要么用切换助手切换回去以前的halcon版本。2、c#里面引用的库换成现在的halcon版本。3、将你已引用的halcondotnet.dll动态链接库,相同版本的Halcon.dll放到degub文件目录下即可。...原创 2020-03-12 13:30:55 · 10890 阅读 · 1 评论 -
C# 截屏幕
try { //获取屏幕宽 int iWidth = Screen.PrimaryScreen.Bounds.Width; //获取屏幕高 int iHeight = Screen.PrimaryScreen.Bounds.Height; ...原创 2020-03-04 14:26:38 · 223 阅读 · 0 评论 -
C# 获取指定磁盘容量
#region 磁盘 /// <summary> /// 获取指定驱动器的空间总大小(单位为GB) /// </summary> /// <param name="str_HardDiskName">只需输入代表驱动器的字母即可</param> /// <re...原创 2020-03-03 15:50:40 · 515 阅读 · 0 评论 -
C# 给日期增加一天、减少一天
DateTime dt = DateTime.Now;string plus= dt.AddDays(2).ToString("yyyyMMddHHmmss");//添加2天string subtract= dt.AddDays(2).ToString("yyyyMMddHHmmss");//减2天原创 2020-02-22 01:48:49 · 5940 阅读 · 2 评论 -
C# 中实现注册表的写入和读取
1、添加命名空间 using Microsoft.Win32;2、读取注册表:RegistryKey regkey=Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");string[] n=regkey.GetValueNames();for(int i=0;i<n....原创 2020-02-17 20:06:57 · 2294 阅读 · 0 评论 -
c# 读写注册表
using Microsoft.Win32;/// <summary>/// 注册表/// </summary>public class Regedit{ private const string SUB_KEY = "SOFTWARE"; private static readonly RegistryKey HKML; priva...原创 2020-02-17 19:48:09 · 172 阅读 · 0 评论 -
C# 读取ini
// <summary> /// INI文件读写类。 /// </summary> public class INIFile { public string path; public INIFile(string INIPath) { path = INIPath; } [DllImport("kernel32")] ...原创 2020-02-16 21:39:31 · 213 阅读 · 0 评论 -
C# 检测指定目录是否存在
#region 检测指定目录是否存在 /// <summary> /// 检测指定目录是否存在 /// </summary> /// <param name="directoryPath">目录的绝对路径</param> /// <returns><...原创 2020-02-16 21:33:35 · 483 阅读 · 0 评论 -
C# 向文本文件的尾部追加内容
#region 向文本文件的尾部追加内容/// <summary>/// 向文本文件的尾部追加内容/// </summary>/// <param name="filePath">文件的绝对路径</param>/// <param name="content">写入的内容</param>public static...原创 2020-02-16 21:28:38 · 4023 阅读 · 0 评论 -
C# 将DataGridView中的数据导入到Csv文件中
#region 将DataGridView中的数据导入到Csv文件中 public static bool dataGridViewToCSV(DataGridView dataGridView) { if (dataGridView.Rows.Count == 0) { M...原创 2019-11-14 20:31:26 · 1000 阅读 · 0 评论 -
C# 将CSV文件的数据读取到DataTable中再写入dataGridView1
调用:dataGridView1.DataSource =readCSV(System.Environment.CurrentDirectory + @"\路径规划.csv"); #region 将CSV文件的数据读取到DataTable中 /// <summary> /// 将CSV文件的数据读取到DataTable中 /// ...原创 2019-11-11 08:52:33 · 4773 阅读 · 1 评论 -
C# 将dataGridView1数据写入CSV
#region 将dataGridView1数据写入CSV /// <summary> /// 将dataGridView1数据写入CSV /// </summary> /// <param name="dataGridView1"></param> public s...原创 2019-11-10 23:52:19 · 752 阅读 · 2 评论 -
C# 将Excel数据写入dataGridView1
try { // strPath = ofd.FileName; string strCon = "provider=microsoft.jet.oledb.4.0;data source=" + Application.StartupPath+ "\\视觉班通...原创 2019-11-01 16:52:32 · 1305 阅读 · 0 评论 -
C# 设置winform窗口只开启一次
Form2窗口 public event EventHandler endform;//委托一个事件关闭窗体触发 private void Correspondence_FormClosed(object sender, FormClosedEventArgs e) { endform(sender, e);//触发事件 }Form1public int frmc...原创 2019-10-29 20:00:14 · 955 阅读 · 0 评论 -
C# 固高运动控制卡插补
在运动控制器的初始状态下,复位之后或者还未使用过插补运动状态下,所有的规划轴都处于单轴运动模式下,两个坐标系也是无效的。进行插补运动时,首先需要建立坐标系,将规划轴映射到相应的坐标系中 。 short sRtn; short cardNum = 0; mc.TCrdPrm crdPrm = new TCrdPrm(); ; ...原创 2019-10-23 09:01:53 · 4410 阅读 · 0 评论 -
C#与halcon联合编程halcon缩放
private static HTuple WindowID, ImageWidth, ImageHeight; private static double RowDown;//鼠标按下时的行坐标 private static double ColDown;//鼠标按下时的列坐标 private static HObject ho_image; ...原创 2019-10-18 22:57:29 · 2844 阅读 · 1 评论