随笔分类 - C#学习随笔
记录C#相关的学习过程与资料
摘要:Application.Current.Dispatcher.Invoke(new Action(()=> { //修改主线程UI绑定属性代码 Nodes = new ObservableCollection<Node>(list); })); //异步模式 Application.Current.
阅读全文
摘要:原文连接 一、添加一個FrameworkElement的代理 <Window.Resources> <FrameworkElement x:Key="ProxyElement" DataContext="{Binding}"/> </Window.Resources> 二、用一個不可見的Conten
阅读全文
摘要:方法一: 挂梯子,但是每次访问github都需要挂梯子,太麻烦了。 方法二(麻烦一点儿): 使用ip查询器,查询github.com的IP地址,随即在浏览器地址栏输入,即可访。 方法三(一劳永逸): 更改C:\Windows\System32\drivers\etc中的hosts文件,使用编辑器打开
阅读全文
摘要:前端代码 <Window x:Class="EVES_ManualTest.CurveForm" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.c
阅读全文
摘要:当ComboBox子项过多时,下拉子项会出现滚动条,这样十分不美观 那么怎么解决呢,十分简单,只需要设置ComboBox的【MaxDropDownHeight】为【Auto】即可 示例代码:(其中 MaxDropDownHeight="Auto" 就是解决代码) <ComboBox Style="{
阅读全文
摘要:效果图: 1、设计DataGrid展示数据模型类 public class DataRecord { public bool IsChecked { get; set; } public DateTime Time { get; set; } public string Title { get; s
阅读全文
摘要:一、调用Winform控件 1、添加 “WindowsFormsIntegration” 程序集引用 2、在前端代码设计处使用命名空间 代码: xmlns:wf="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsForms
阅读全文
摘要:错误指示:通信端口被占用了,导致通信无法进行。 有可能是已经启动了一个程序,还有一种可能是端口被别人占用了 查看启动程序的端口使用情况: 比如端口:80 1.netstat -aon|findstr “80” 查看占用8086端口的进程 2.查找占用端口句柄的程序:tasklist | findst
阅读全文
摘要:使用命名空间System.Runtime.InteropServices using System.Runtime.InteropServices; 调用API方法 /// <summary> /// 获得当前活动窗体的句柄 /// </summary> /// <returns>返回窗体句柄</r
阅读全文
摘要:Console.WriteLine("主显示器完整尺寸:"); Console.WriteLine("宽:" + Screen.PrimaryScreen.Bounds.Width); Console.WriteLine("高:" + Screen.PrimaryScreen.Bounds.Heig
阅读全文
摘要:代码如下: /// <summary> /// 将Image转化为Byte数组 /// </summary> /// <param name="img">要转化的图像</param> /// <returns>返回转化后的Byte字节数组</returns> public byte[] GetByt
阅读全文
摘要:一、关闭任务栏显示 ShowInTaskbar =false;//关闭任务栏显示,直接写在窗体加载事件 二、右下角小图标显示,使用NotifyIcon控件 三、为右下角图标添加右键菜单,使用ContextMenuStrip1,再将该菜单控件绑定到右下角图标控件
阅读全文
摘要:方法一:调用Windows API来实现窗口置顶。 1.使用命名空间 using System.Runtime.InteropServices; 2、声明Windonws API方法 [DllImport("user32.dll", EntryPoint = "SetWindowPos")] pub
阅读全文
摘要:Modbus介绍1、起源 Modbus 通信协议,是一种工业现场总线协议标准。 Modbus通信协议具有多个变种,其中有支持串口,以太网多个版本,主要有以下三种: Modbus RTU、Modbus ASCII和Modbus TCP 优势: 免费、简单、容易使用 2、分类:(1)Modbus RTU
阅读全文
摘要:原文连接 浮点数保存的字节格式如下: 地址 +0 +1 +2 +3内容 SEEE EEEE EMMM MMMM MMMM MMMM MMMM MMMM 这里S 代表符号位,1是负,0是正E 偏移127的幂,二进制阶码=(EEEEEEEE)-127。M 24位的尾数保存在23位中,只存储23位,最高位
阅读全文
摘要:int类型的最大值: 2147483647,最小值: -2147483648 uint类型的最大值: 4294967295,最小值: 0 byte类型的最大值: 255,最小值: 0 sbyte类型的最大值: 127,最小值: -128 short类型的最大值: 32767,最小值: -32768
阅读全文
摘要:代码如下 /// <summary> /// //16转2方法 /// </summary> /// <param name="hexString"></param> /// <returns></returns> static string HexString2BinString(string h
阅读全文
摘要:原文连接 方法一: int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(DateTime.Now.Year ,DateTime.Now.Month); 方法二: DateT
阅读全文
摘要:一、什么是Stopwatch Stopwatch:提供一组方法和属性,可以准确的测量运行时间。使用的时候需要引用命名空间:System.Diagnostics。 二、Stopwatch的简单使用 //创建Stopwatch实例 Stopwatch sw = new Stopwatch(); //开始
阅读全文
摘要:c# byte类型 在C#中,byte类型表示一个8位无符号整数(也称为字节)。由于它是无符号的,它的值范围是0到255。 声明和初始化 byte类型的变量可以像其他变量一样进行声明和初始化。以下是一些示例: byte b1 = 100; byte b2 = byte.MaxValue; byte
阅读全文