随笔分类 - C#
摘要:public static int ushorts2int(ushort[] res) { int high = res[0]; int low = res[1]; int value = (high << 16) + low; return value; } public static ushor
阅读全文
摘要:使用{0:P}与{0:P2}具有相同的效果,即格式化为百分比,严格显示两位小数. 我终于用{0:0.################################来代替有问题的{0:P}. %}.为了我的目的,我的双打没有达到那么多的小数. string.Format("{0:0.########
阅读全文
摘要:下载Nuget包:EMGU.CV(测试用版本:4.0.1.3373) ; public void InitVideo() { VideoCapture _capture = new VideoCapture("rtsp://admin:123456@192.168.1.237:554"); Thre
阅读全文
摘要:long time=(now.ToUniversalTime().Ticks - 621355968000000000) / 10000000; //时间戳 bt[x++] = (byte)(time >> 24); bt[x++] = (byte)((time >> 16) & 0xFF); bt
阅读全文
摘要:private string hexStrToStr(string str) { //去除字符串中的空格 string[] strT = str.Split(' '); string strA = ""; foreach (string strB in strT) { strA += strB; }
阅读全文
摘要:WPF 窗口大小自适应 在设置桌面不同分辨率以及较大DPI下,窗口如何显示的问题。 方案一 设置窗口最大值和最小值显示 通过对比当前屏幕的可显示区域,将窗口高宽最大值和最小值,设置为窗口的实际高宽(此例中仅设置高度) 界面设置 设置窗口内容自适应SizeToContent="WidthAndHeig
阅读全文
摘要:<Window.Resources> </Window.Resources>
阅读全文
摘要:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.
阅读全文
摘要:public void TestA() { int time = 1658310821; string str = time.ToString("X4"); byte[] testb = strToHexByte(str); } /// <summary> /// 16进制字符串转换成16进制byt
阅读全文
摘要:public void Test() { byte[] results = new byte[1]; results[0] = 0xff; int temp = results[0]; byte b = SetBit(results[0], 7, 0); Console.WriteLine(b);
阅读全文
摘要:/// /// 获取字节中的指定Bit的值 /// /// 字节 /// Bit的索引值(0-7) /// public int GetBit(byte test, int index) { byte x = 1; switch (index) { case 0: { x = 0x01; } bre
阅读全文
摘要:using System.Web; 引用system.web。 textBox2.Text = System.Web.HttpUtility.UrlDecode(textBox1.Text, System.Text.Encoding.GetEncoding("GB2312"));//将Url中的编码
阅读全文
摘要:WPF程序最大化被任务栏遮挡的解决办法 this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight; this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth; WINF
阅读全文
摘要:string postString = "arg1=a&arg2=b";//这里即为传递的参数,可以用工具抓包分析,也可以自己分析,主要是form里面每一个name都要加进来 byte[] postData = Encoding.UTF8.GetBytes(postString);//编码,尤其是汉
阅读全文
摘要:C# 依赖注入 依赖注入是一个过程,就是当一个类需要调用另一个类来完成某项任务的时候,在调用类里面不要去new被调用的类的对象,而是通过注入的方式来获取这样一个对象。具体的实现就是在调用类里面有一个被调用类的接口,然后通过调用接口的函数来完成任务; 依赖注入最常用的两种方式是setter注入和构造函
阅读全文
摘要:public bool IsBookBeOverdue(DateTime _beTime) { bool resultFlg = false; int compNum = DateTime.Compare(DateTime.Now, _beTime); //t1> t2 if (compNum >
阅读全文
摘要://将含有正确日期格式的string类型转换成DateTime类型 string strDate = "2014-08-01"; DateTime dt1 = Convert.ToDateTime(strDate); //将包含时分秒的string类型日期转换成DateTime类型 string s
阅读全文
摘要:public List ReadeCFGNameFromExcel(string ExcelName) { List ColumnDB = new List(); //创建 Excel对象 Microsoft.Office.Interop.Excel.Application App = new Mi
阅读全文
摘要:HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;//窗口过程 if (hwndSource != null) { hwndSource.AddHook(new HwndSourceHook(Devei
阅读全文
摘要:/// /// GB2312转换成UTF8 /// /// /// public static string gb2312_utf8(string text) { //声明字符集 System.Text.Encoding utf8, gb2312; //gb2312 gb2312 = System.
阅读全文