随笔分类 - C#
摘要:字符串转rtf值 //字符串转rtf public string str2Rtf(string s) { string rtfFormattedString = ""; RichTextBox richTextBox = new RichTextBox(); richTextBox.Text = s
阅读全文
摘要:打开文件 ```C# private void selectFile() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Files|*.png;*.jpg"; // 设定打开的文件类
阅读全文
摘要:public static bool DownLoadFiles(string uri, string filefullpath, int size = 1024) { try { if (File.Exists(filefullpath)) { try { File.Delete(filefull
阅读全文
摘要:等比例压缩 /// <summary> /// 压缩图片 /// </summary> /// <param name="filePath">文件路径</param> /// <param name="height">图像高度</param> /// <returns></returns> publ
阅读全文
摘要:/// <summary> /// 写文件导到磁盘(异步) /// </summary> /// <param name="stream">数据流</param> /// <param name="path">文件路径</param> /// <returns></returns> public s
阅读全文
摘要:AES加密与解密 /// <summary> /// AES 加密 /// </summary> /// <param name="str">明文</param> /// <param name="aesKey">密钥</param> /// <returns></returns> public
阅读全文
摘要:/// <summary> /// 随机数 /// </summary> /// <param name="Length">长度</param> /// <returns></returns> public static string GenerateRandomNumber(int Length)
阅读全文
摘要:播放Mp3音频 /// <summary> /// 播放音频, /// 1.添加新引用 COM组件的Microsoft Shell Controls And Automation /// 2.添加成功,引用中显示的为Shell32.dll,、 /// 3.设置Shell32.dll的属性为嵌入互操作
阅读全文
摘要:计算音频的时长 /// <summary> /// 获取mp3文件的歌曲时间长度 /// </summary> /// <param name="songPath"></param> /// <returns></returns> private string GetMp3Times(string
阅读全文
摘要:获取本机IP /// <summary> /// 获取本机IP地址 /// </summary> /// <returns></returns> private string GetHostAddressIP() { IPHostEntry ipHostEntry = Dns.GetHostEntr
阅读全文
摘要:删除时间范围外文件 private static void DeleteOldLogs() { try { // string s =Directory.GetCurrentDirectory(); var path = Application.StartupPath + "\\ErrLog"; i
阅读全文
摘要:根据进程名称关闭 public static void KillProcess(string Pname) { foreach (var v in Process.GetProcessesByName(Pname) { v.Kill(); } }
阅读全文
摘要:窗体关闭事件 private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) { try { if (e.CloseReason == CloseReason.UserClosing) { if (MessageBox.
阅读全文
摘要:public static void Log(string category, string log) { try { if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Err
阅读全文
摘要:###案例学习笔记 class AutoResetEventTest { const int numIterations = 10; static AutoResetEvent myResetEvent = new AutoResetEvent(false); static AutoResetEve
阅读全文
摘要:foreach (Form f in Application.OpenForms) { if (f.Name == "Form1") { if (f.WindowState == FormWindowState.Minimized) { f.WindowState = FormWindowState
阅读全文
摘要:时间戳转时间 ```C# private void getTimeByMillsSpan() { string createTime = "1654591477438";//时间毫秒差 double timeVal = double.Parse(createTime);//字符串转为double,
阅读全文
摘要:C#创建文件以及写文件 创建文件 public static bool CreateFile(string FileName, ref string strErr) { bool flag = false; try { if (File.Exists(FileName)) File.Delete(F
阅读全文
摘要:多态: 多态是同一个行为具有多个不同表现形式或形态的能力。 多态的应用场景: (1)将父类作为参数进行传递。 (2)将父类作为返回值。 案例一:将父类作为参数传递(模拟人和动物打招呼) 首先看如下代码的缺陷: class Dog { public void Speaking() { Console.
阅读全文
摘要:继承:让类之间存在父子关系,子类可以继承父类的属性和方法,简化代码。 继承特点: (1) 子类拥有父类非 private 的属性、方法。 (2) 子类可以拥有自己的属性和方法,即子类可以对父类进行扩展。 (3) 一个父类可以有多个子类 ,一个子类不能有多个父类(即单继承)。 (4) 继承可以多重继承
阅读全文