随笔分类 - C#
摘要:Publicfile publicfile = new Publicfile(); try { string filePath = Path.Combine("C:?", fileName); if (!File.Exists(filePath)) { WriteErrorLog($"File({f
阅读全文
摘要:Publicfile publicfile = new Publicfile(); publicfile.FileName = "TESTFILE"; publicfile.Position1 = 100; Type type = typeof(Publicfile); PropertyInfo[]
阅读全文
摘要:using System; using System.Reflection; public class MyClass { public int Property1 { get; set; } = 42; public string Property2 { get; set; } = "Hello,
阅读全文
摘要:XDocument document = new XDocument(new XDeclaration("1.0","utf-8",null)); XElement root = new XElement("root"); root.SetAttributeValue("Name", "Config
阅读全文
摘要:安装好VisionPro后,默认组件路径: C:\Program Files\Cognex\VisionPro\ReferencedAssemblies\Cognex.VisionPro.Controls.dll 将dll拖入工具箱即可使用。
阅读全文
摘要:比如: int i = 1; if (i != 100 && i != 200 && i != 300) { return; } 优化: int i = 1; if (!new[] { 100, 200, 300 }.Contains(i)) { return; } 这样后续增加匹配数据,只需要把检
阅读全文
摘要:string ip = "127.0.0.1"; //要检查的IP地址 Ping pingSender = new Ping(); try { PingReply reply = pingSender.Send(ip, 120); if (reply.Status == IPStatus.Succe
阅读全文
摘要:问题解决一: 如果是窗体属性加载了背景图导致的内存占用,在关闭窗体前,释放掉背景图资源即可释放占用的内存 private Image backgroundImage; public Form2() { InitializeComponent(); backgroundImage = Image.Fr
阅读全文
摘要:我用的是Caliburn Micro框架,自建框架或者使用其它框架的可自行替换绑定部分即可。 效果图: 消息窗体View代码: <Window x:Class="WpfAppTest.Views.MsgBoxView" xmlns="http://schemas.microsoft.com/winf
阅读全文
摘要:string strA = "ahjeibnkwed"; string strB = "oiopqdibnwaaldo"; int iMax = 0;//公共子串的最大长度 int iEnd = 0;//公共子串的起始位置 int iA = strA.Length; int iB = strB.Le
阅读全文
摘要:最近项目需求,在网上找了一个处理3D点云文件的源码,但是发现无法编译,研究了下原来是电脑环境问题,必须配置一个PCL库的环境才能使用,下面进入正题。 首先需要安装PCL环境,可以通过vcpkg安装(因为我没有成功,所以请自行查找),我是一直卡在装载pcl环节失败,网上搜了很多解决方法,包括重装VS英
阅读全文
摘要:解决问题:1)当需要抓取显示器分辨率的缩放比例时。2)当屏幕显示缩放设置不等于100%,导致分辨率改变,Screen.PrimaryScreen.Bounds抓取不到实际设置的分辨率时。 解决方案:使用GetDeviceCaps函数。 /// <summary> /// 设备数据函数 /// </s
阅读全文
摘要:step1:NuGet安装Costura.Fody和Fody step2:安装后,打开根目录下的FodyWeavers.xml文件,将内容替换如下后,再执行编译即可封装dll <Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
阅读全文
摘要:第一种方法:抓取程序的进程名,在系统已运行进程中检索该进程名是否已经存在 //获取欲启动进程名 string strProcessName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; //检查进程是否已经启动,已经启动则
阅读全文
摘要:static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += Applicatio
阅读全文
摘要:int iFormWidth, iFormHeight;//初始窗体宽高 //窗体加载事件 private void Form1_Load(object sender, EventArgs e) { iFormWidth = this.Width;//初始宽 iFormHeight = this.H
阅读全文
摘要:protected bool getTimeSpan(string timeStr) { //判断当前时间是否在工作时间段内 string _strWorkingDayAM = "07:00"; string _strWorkingDayPM = "19:00"; TimeSpan dspWorki
阅读全文
摘要:using System.Net.Mail; MailMessage mmsg = new MailMessage(); mmsg.From = new MailAddress("");//发件邮箱地址 mmsg.To.Add("");//收件邮箱地址 mmsg.Subject = "";//邮件标
阅读全文
摘要:using System.Speech.Synthesis; SpeechSynthesizer speech = new SpeechSynthesizer(); speech.Speak("");//同步 speech.SpeakAsync("");//异步
阅读全文
摘要:引用System.Management安装包。 using System.Management; ManagementObjectSearcher mydisplayResolution = new ManagementObjectSearcher("SELECT CurrentHorizontal
阅读全文