当前位置: 首页 > news >正文

C#项目实战

事件
public delegate void NumManipulationHandler(NumEventArgs e);
// 基于上面的委托定义事件
public event NumManipulationHandler ChangeNum;public class Program{public static void Main(){NumEvent even = new NumEvent(0);even.ChangeNum += EventAction.Action;even.SetValue(7);even.SetValue(11);System.Console.ReadKey();}}public class NumEvent{private int value;public delegate void NumManipulationHandler(NumEventArgs e);public event NumManipulationHandler ChangeNum;public virtual void OnChangeNum(NumEventArgs e){ChangeNum?.Invoke(e);}public NumEvent(int n){SetValue(n);}public void SetValue(int n){if (value != n){NumEventArgs e = new NumEventArgs(n);value = n;OnChangeNum(e);}}}public class EventAction{public static void Action(NumEventArgs e){System.Console.WriteLine("value : " + e.value);}}public class NumEventArgs : EventArgs{public int value;public NumEventArgs(int _value){this.value = _value;}}
ini读写 
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;namespace DEMOBus
{public class IniFile{private string m_FileName;public string FileName{get { return m_FileName; }set { m_FileName = value; }}[DllImport("kernel32.dll")]private static extern int GetPrivateProfileInt(string lpAppName,string lpKeyName,int nDefault,string lpFileName);[DllImport("kernel32.dll")]private static extern int GetPrivateProfileString(string lpAppName,string lpKeyName,string lpDefault,StringBuilder lpReturnedString,int nSize,string lpFileName);[DllImport("kernel32.dll")]private static extern int WritePrivateProfileString(string lpAppName,string lpKeyName,string lpString,string lpFileName);/// <summary>/// 构造函数/// </summary>/// <param name="aFileName">Ini文件路径</param>public IniFile(string aFileName){this.m_FileName = aFileName;}/// <summary>/// 构造函数/// </summary>public IniFile(){ }/// <summary>/// [扩展]读Int数值/// </summary>/// <param name="section">节</param>/// <param name="name">键</param>/// <param name="def">默认值</param>/// <returns></returns>public int ReadInt(string section, string name, int def){return GetPrivateProfileInt(section, name, def, this.m_FileName);}/// <summary>/// [扩展]读取string字符串/// </summary>/// <param name="section">节</param>/// <param name="name">键</param>/// <param name="def">默认值</param>/// <returns></returns>public string ReadString(string section, string name, string def){StringBuilder vRetSb = new StringBuilder(2048);GetPrivateProfileString(section, name, def, vRetSb, 2048, this.m_FileName);return vRetSb.ToString();}/// <summary>/// [扩展]写入Int数值,如果不存在 节-键,则会自动创建/// </summary>/// <param name="section">节</param>/// <param name="name">键</param>/// <param name="Ival">写入值</param>public void WriteInt(string section, string name, int Ival){WritePrivateProfileString(section, name, Ival.ToString(), this.m_FileName);}/// <summary>/// [扩展]写入String字符串,如果不存在 节-键,则会自动创建/// </summary>/// <param name="section">节</param>/// <param name="name">键</param>/// <param name="strVal">写入值</param>public void WriteString(string section, string name, string strVal){WritePrivateProfileString(section, name, strVal, this.m_FileName);}/// <summary>/// 删除指定的 节/// </summary>/// <param name="section"></param>public void DeleteSection(string section){WritePrivateProfileString(section, null, null, this.m_FileName);}/// <summary>/// 删除全部 节/// </summary>public void DeleteAllSection(){WritePrivateProfileString(null, null, null, this.m_FileName);}/// <summary>/// 读取指定 节-键 的值/// </summary>/// <param name="section"></param>/// <param name="name"></param>/// <returns></returns>public string IniReadValue(string section, string name){StringBuilder strSb = new StringBuilder(256);GetPrivateProfileString(section, name, "", strSb, 256, this.m_FileName);return strSb.ToString();}/// <summary>/// 写入指定值,如果不存在 节-键,则会自动创建/// </summary>/// <param name="section"></param>/// <param name="name"></param>/// <param name="value"></param>public void IniWriteValue(string section, string name, string value){WritePrivateProfileString(section, name, value, this.m_FileName);}}
}
绘图 
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;namespace _949CS//实时曲线绘制
{class draw{public List<Point> ptlist = new List<Point> { new Point(0, 0)};public PictureBox picbox = new PictureBox();public Bitmap mybitmap;//用于双缓冲的位图,和画布等大public Int32 xMoveToUp = 0, yMoveToRight = 0;     //X上移距离与Y右移距离public Int32 xToLeft = 5, xToRight = 10, yToUp = 5, yToDown = 5; //XY图像边距,x轴起点离左边距,终点右边距,y轴起点下边距,上边距,Y轴坐标为从上往下递增值public void DrawLineS(Color color, float Xmax, float Ymax){if (ptlist.Count < 2){//空返回return;}mybitmap = new Bitmap(picbox.Width, picbox.Height);//设定位图大小Graphics doublebufferg = Graphics.FromImage(mybitmap);//从位图上获取“画布”doublebufferg.Clear(Color.Black);//用背景色刷新//picbox填充为白色,便于显示图像  500*300Rectangle rect = new Rectangle(0, 0, picbox.Width, picbox.Height);doublebufferg.FillRectangle(new SolidBrush(Color.Black), rect);//画X和Y轴DrawXY(ref doublebufferg, picbox);//X轴上的刻度SetYAxis(ref doublebufferg, picbox, Ymax);//Y轴上的刻度SetXAxis(ref doublebufferg, picbox, Xmax);Point[] pt = ptlist.ToArray();Int32 i = 0;for (i = 0; i < pt.Length; i++){pt[i].X += xToLeft + yMoveToRight;//自定义坐标转换pt[i].Y = picbox.Height - yToDown - xMoveToUp - pt[i].Y;if (i > 0){//要显示的实时曲线部分doublebufferg.DrawLine(new Pen(color, 1), pt[i - 1], pt[i]);}}//将缓冲中的位图绘制到我们的窗体上if (!picbox.IsDisposed){   //是够释放picbox.BackColor = Color.Black;     //背景色直接设置(picbox.CreateGraphics()).DrawImage(mybitmap, 0, 0);}} //X上移public void  SetMoveX(Int32 x){xMoveToUp = x;}//Y右移public void  SetMoveY(Int32 y){yMoveToRight = y;}//完成X轴和Y轴的基本部分public void  DrawXY(ref Graphics g,PictureBox picbox){Pen pen = new Pen(Color.White, 2);//画笔SolidBrush sb = new SolidBrush(Color.White);//话刷//X轴的箭头,实际上是绘制了一个三角形Int32 arrorWidth = 5, arrorHeight = 2;   //箭头的三角形中位线长与底边长一半Point[] xpts = new Point[3] {   //自定义坐标转换new Point(picbox.Width - (xToRight + arrorWidth), picbox.Height - (arrorHeight + yToDown + xMoveToUp)),new Point(picbox.Width - xToRight, picbox.Height - yToDown - xMoveToUp),new Point(picbox.Width - (xToRight + arrorWidth), picbox.Height + arrorHeight - yToDown - xMoveToUp)};g.DrawLine(pen, xToLeft, picbox.Height - yToDown - xMoveToUp, picbox.Width - xToRight, picbox.Height - yToDown - xMoveToUp);g.DrawPolygon(pen, xpts);//自定义坐标转换g.DrawString("X", new Font("宋体", 11), sb, picbox.Width - (xToRight), picbox.Height - (yToDown + xMoveToUp));//Y轴的箭头,实际上是绘制了一个三角形Point[] ypts = new Point[3] { //自定义坐标转换new Point(xToLeft + yMoveToRight - arrorHeight, yToUp + arrorHeight),new Point(xToLeft + yMoveToRight, yToUp), new Point(xToLeft + yMoveToRight + arrorHeight, yToUp + arrorHeight)};g.DrawLine(pen, xToLeft + yMoveToRight, picbox.Height - yToDown, xToLeft + yMoveToRight, yToUp);g.DrawPolygon(pen, ypts);//自定义坐标转换g.DrawString("Y", new Font("宋体", 11), sb, yMoveToRight + xToLeft + arrorHeight, 0);}//绘制Y轴上的刻度public void SetYAxis(ref Graphics g,PictureBox picbox, float YMAX){Pen p1 = new Pen(Color.Goldenrod, 1);Pen p2 = new Pen(Color.White, 2);SolidBrush sb = new SolidBrush(Color.White);float ykedu = YMAX / 200;//给定的最大刻度与实际像素的比例关系=,未优化,目前为1:1//第一个刻度的两个端点float xl = xToLeft - 3 + yMoveToRight, yl = picbox.Height - yToUp, xr = xToLeft + 3 + yMoveToRight, yr = picbox.Height - yToDown;//自定义坐标转换for (int j = 0; j < picbox.Height - (yToDown + yToUp); j += 10){if (j % 50 == 0)//一个大的刻度,黑色,每隔50像素一个{g.DrawLine(p2, xl, yl - j, xr, yl - j);//刻度线string tempy = ((j - xMoveToUp - yToDown) * ykedu).ToString();//自定义坐标转换g.DrawString(tempy, new Font("宋体", 8), sb, xl - 20, yl - j - 5);}else//小刻度,金黄色,10像素一个{ g.DrawLine(p1, xl, yl - j, xr, yl - j); }}}//绘制x轴上的刻度public void SetXAxis(ref Graphics g,PictureBox picbox, float XMAX){Pen p1 = new Pen(Color.Goldenrod, 1);Pen p2 = new Pen(Color.White, 2);SolidBrush sb = new SolidBrush(Color.White);float xkedu = XMAX / 400;  //比例关系未优化,目前为1:1float xt = xToLeft, yt = picbox.Height - yToDown - 3 - xMoveToUp, xb = xToLeft, yb = picbox.Height - yToDown + 3 - xMoveToUp;//自定义坐标转换for (int i = 0; i < picbox.Width - (xToLeft + xToRight); i += 10){if (i % 50 == 0){g.DrawLine(p2, xt + i, yt, xb + i, yb);string tempx = ((i - yMoveToRight - xToLeft) * xkedu).ToString();//自定义坐标转换g.DrawString(tempx, new Font("宋体", 8), sb, xt + i - 7, picbox.Height - 25 - xMoveToUp);}else { g.DrawLine(p1, xt + i, yt, xb + i, yb); }}}}}
CListCtrlEx重载 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;namespace ADT_LISTVIEW
{enum LIST_TYPE{NO_TYPE = -1,EDIT_TYPE = 0,CBO_TYPE = 1,}class ListViewEx : ListView{private TextBox m_tb;private ComboBox m_cb;private bool m_bCheckBox;private Int32[ ] m_lst = new Int32[20];     //支持最大列数20private string[] m_str = new string[20];       //最大列字符串20public void SetChekBox(bool bCheck){ m_bCheckBox = bCheck; }public void AddCboString(String str) {string[] param = str.Split(':');m_cb.Items.Clear();foreach (string i in param){m_cb.Items.Add(i);}m_cb.SelectedIndex = 0;}public void SetListType(int nIndex, int type){m_lst[nIndex] = type;        }public int FindStringInCbo(int nCol, string str){if (m_lst[nCol] != 1){return -1;}else{AddCboString(m_str[nCol]);return m_cb.FindString(str, -1);}}public ListViewEx(){m_tb = new TextBox();m_cb = new ComboBox();m_tb.Multiline = false;m_tb.Visible = false;m_cb.Visible = false;m_cb.DropDownStyle = ComboBoxStyle.DropDownList;m_cb.IntegralHeight = true;this.GridLines = true;this.CheckBoxes = true;this.FullRowSelect = false;SetChekBox(this.CheckBoxes);this.Controls.Add(m_tb);this.Controls.Add(m_cb);for (int i = 0; i < 20; i++){SetListType(i, 0);}SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);  //解决ListView闪烁问题}public void Insert(int nIndex, ListViewItem item){for (int i = 0; i < item.SubItems.Count; i++ ){   //保存所有列字符——最多20m_str[i] = item.SubItems[i].Text;if (m_str[i].IndexOf(':') > 0){SetListType(i, 1);AddCboString(m_str[i]);item.SubItems[i].Text = m_cb.Text;}else{SetListType(i, 0);}}this.Items.Insert(nIndex, item);}private void EditItem(ListViewItem.ListViewSubItem subItem){if (this.SelectedItems.Count <= 0){return;}Rectangle _rect = subItem.Bounds;m_tb.Bounds = _rect;ListViewItem lvi = this.SelectedItems[0];   //选中的多行第0行if (subItem == lvi.SubItems[0] || 0 == subItem.Bounds.X){   //第一列为复选框if (m_bCheckBox){return;}else{   //修复宽度m_tb.Width = this.Columns[0].Width;}}m_tb.BringToFront();m_tb.Text = subItem.Text;m_tb.Leave += new EventHandler(tb_Leave);m_tb.TextChanged += new EventHandler(m_tb_TextChanged);m_tb.Visible = true;m_tb.Tag = subItem;m_tb.Select();}private void EditItem(ListViewItem.ListViewSubItem subItem, Rectangle rt){if (this.SelectedItems.Count <= 0){return;}Rectangle _rect = rt;m_cb.Bounds = _rect;m_cb.BringToFront();// m_cb.Items.Add(subItem.Text);m_cb.Text = subItem.Text;m_cb.Leave += new EventHandler(lstb_Leave);m_cb.TextChanged += new EventHandler(m_lstb_TextChanged);m_cb.DropDownClosed += new EventHandler(m_lstb_TextChanged);m_cb.DropDown += new EventHandler(m_lstb_DropDown);m_cb.LostFocus += new EventHandler(lstb_Lost);m_cb.Visible = true;m_cb.Tag = subItem;m_cb.Select();}protected override void OnKeyDown(KeyEventArgs e){
//             if (e.KeyCode == Keys.F2)
//             {
// 
//                 if (this.SelectedItems.Count > 0)
//                 {
//                     this.SelectedItems[1].BeginEdit();
//                     ListViewItem lvi = this.SelectedItems[0];
//                     EditItem(lvi.SubItems[0], new Rectangle(lvi.Bounds.Left, lvi.Bounds.Top, this.Columns[0].Width, lvi.Bounds.Height - 2));
//                 }
//             }base.OnKeyDown(e);}protected override void OnSelectedIndexChanged(EventArgs e){this.m_tb.Visible = false;this.m_cb.Visible = false;base.OnSelectedIndexChanged(e);}protected override void OnDoubleClick(EventArgs e){Point tmpPoint = this.PointToClient(Cursor.Position);ListViewItem.ListViewSubItem subitem = this.HitTest(tmpPoint).SubItem;ListViewItem item = this.HitTest(tmpPoint).Item;if (subitem != null){int nIndex = 0;item.Checked = !item.Checked;       //修复双击时反选功能if (0 == subitem.Bounds.X){//修复第一列nIndex = 0;}else{nIndex = this.SelectedItems[0].SubItems.IndexOf(subitem);if (nIndex > this.Columns.Count){   //修复频繁点击时索引不更新bugbase.OnDoubleClick(e);return;}}if (0 == m_lst[nIndex]){  //类型选择,编辑框EditItem(subitem);}else if (1 == m_lst[nIndex]){  //组合框AddCboString(m_str[nIndex]);EditItem(subitem, new Rectangle(subitem.Bounds.Left, subitem.Bounds.Top, this.Columns[nIndex].Width, subitem.Bounds.Height - 2));}else{;}//item.Checked = !item.Checked;}base.OnDoubleClick(e);}
//         protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
//         {
//             m_cb.Hide();
//             base.OnDrawColumnHeader(e);
//         }protected override void WndProc(ref   Message m){if (m.Msg == 0x115 || m.Msg == 0x114){this.m_tb.Visible = false;this.m_cb.Visible = false;}base.WndProc(ref   m);}private void tb_Leave(object sender, EventArgs e){m_tb.TextChanged -= new EventHandler(m_tb_TextChanged);(sender as TextBox).Visible = false;}private void m_tb_TextChanged(object sender, EventArgs e){if ((sender as TextBox).Tag is ListViewItem.ListViewSubItem){(this.m_tb.Tag as ListViewItem.ListViewSubItem).Text = this.m_tb.Text;}}private void lstb_Leave(object sender, EventArgs e){m_cb.TextChanged -= new EventHandler(m_lstb_TextChanged);m_cb.DropDownClosed -= new EventHandler(m_lstb_TextChanged);m_cb.DropDownClosed -= new EventHandler(m_lstb_DropDown);m_cb.DropDown -= new EventHandler(m_lstb_DropDown);m_cb.LostFocus -= new EventHandler(lstb_Lost);}private void m_lstb_TextChanged(object sender, EventArgs e){if ((sender as ComboBox).Tag is ListViewItem.ListViewSubItem){(this.m_cb.Tag as ListViewItem.ListViewSubItem).Text = this.m_cb.Text;}}private void m_lstb_DropDown(object sender, EventArgs e){if ((sender as ComboBox).Tag is ListViewItem.ListViewSubItem){this.m_cb.Text = (this.m_cb.Tag as ListViewItem.ListViewSubItem).Text;}}private void lstb_Lost(object sender, EventArgs e){m_cb.Hide();    //隐藏lstb_Leave(sender, e);}}
}

 

参考

FastTunnel: 开源免费跨平台 内网穿透 远程内网电脑 自定义域名访问内网站点 反向代理内网服务 http代理 类花生壳 端口转发 微信 小程序 frp NAT ssh proxy tunnel ngork

GitHub - HandyOrg/HandyControl: Contains some simple and commonly used WPF controls 

https://github.com/OfficeDev/Image-FileHandler

https://github.com/probot/no-response

https://github.com/dotnet/Open-XML-SDK

https://github.com/OfficeDev/PnP-WOPI

https://github.com/OfficeDev/Open-XML-SDK

https://github.com/OfficeDev/Excel-IO

GitHub - cnxy/files-uwp: A modern file explorer that pushes the boundaries of the platform.

GitHub - OfficeDev/office-fluent-ui-command-identifiers: Office Fluent User Interface Control Identifiers

Code of Conduct | Microsoft Open Source

https://github.com/CollaboratingPlatypus/PetaPoco

https://www.cnblogs.com/zhangweizhong/p/3718549.html

NuGet Gallery | PetaPoco 5.1.304

https://www.cnblogs.com/zhangweizhong/category/855479.html

https://www.cnblogs.com/zhangweizhong/category/771056.html

https://github.com/LonelyCodelang?tab=repositories

https://worktile.com/share/files/64a3b9c8ec0a4d3d81b89a630177c880

https://github.com/statianzo/PostLog

https://www.cnblogs.com/zhangweizhong/category/771055.html

https://github.com/statianzo/Fleck

https://github.com/EasyHttp/EasyHttp

GitHub - Tencent/xLua: xLua is a lua programming solution for C# ( Unity, .Net, Mono) , it supports android, ios, windows, linux, osx, etc.

QJ_FileCenter: 企捷Lotus文件管理平台是开源文档管理平台/企业网盘,支持企业文件、个人文件等文件分库管理,平台能够满足统一存储、文件共享功能。并提供文件上传、目录维护、重命名、移动、复制、删除、预览、等功能。

需ngnix反向代理,账号admin,密码abc123.搭建个人云盘

企捷科技 - 企捷科技

https://gitee.com/dotnetchina/BootstrapAdmin

dotNET China: 让 .NET 开发更简单,更通用,更流行。

GitHub - files-community/Files: Building the best file manager for Windows

GitHub - MMmmmoko/Bongo-Cat-Mver: An Bongo Cat overlay written in C++


创作不易,小小的支持一下吧!

相关文章:

  • 数据中台、数据仓库、数据湖的区别和关联
  • 装机必备 - WinRAR安装教程
  • 电子书资源汇总
  • C++基础与深度解析 | 类与面向对象编程 | 数据成员 | 成员函数 | 访问限定符与友元 | 构造、析构成员函数 | 字面值类、成员指针与bind交互
  • 47-1 等级保护工作流程
  • Hexo+Github搭建个人博客教程
  • 【图书推荐】《分布式数据库HBase案例教程》
  • 论文写作革新:AI如何简化你的研究流程?
  • adb 常用命令
  • Java--递归
  • minio多节点部署
  • DevOps的原理及应用详解(二)
  • STM32智能家居项目esp8266上云OneNet【附源码+详细教程】
  • 机床联网第一课
  • Spring Boot 项目启动时在 prepareContext 阶段做了哪些事?
  • [rust! #004] [译] Rust 的内置 Traits, 使用场景, 方式, 和原因
  • 「前端」从UglifyJSPlugin强制开启css压缩探究webpack插件运行机制
  • 【刷算法】从上往下打印二叉树
  • crontab执行失败的多种原因
  • CSS3 聊天气泡框以及 inherit、currentColor 关键字
  • Eureka 2.0 开源流产,真的对你影响很大吗?
  • java 多线程基础, 我觉得还是有必要看看的
  • javascript数组去重/查找/插入/删除
  • Laravel Telescope:优雅的应用调试工具
  • react-native 安卓真机环境搭建
  • 如何选择开源的机器学习框架?
  • 使用Swoole加速Laravel(正式环境中)
  • 吴恩达Deep Learning课程练习题参考答案——R语言版
  • 自动记录MySQL慢查询快照脚本
  • CMake 入门1/5:基于阿里云 ECS搭建体验环境
  • MyCAT水平分库
  • ​直流电和交流电有什么区别为什么这个时候又要变成直流电呢?交流转换到直流(整流器)直流变交流(逆变器)​
  • # Maven错误Error executing Maven
  • #AngularJS#$sce.trustAsResourceUrl
  • #nginx配置案例
  • (1)(1.19) TeraRanger One/EVO测距仪
  • (cos^2 X)的定积分,求积分 ∫sin^2(x) dx
  • (C语言)编写程序将一个4×4的数组进行顺时针旋转90度后输出。
  • (day6) 319. 灯泡开关
  • (k8s中)docker netty OOM问题记录
  • (Oracle)SQL优化基础(三):看懂执行计划顺序
  • (Python第六天)文件处理
  • (笔记自用)LeetCode:快乐数
  • (差分)胡桃爱原石
  • (二)hibernate配置管理
  • (二十六)Java 数据结构
  • (附源码)springboot建达集团公司平台 毕业设计 141538
  • (附源码)ssm基于微信小程序的疫苗管理系统 毕业设计 092354
  • (四) Graphivz 颜色选择
  • .mp4格式的视频为何不能通过video标签在chrome浏览器中播放?
  • .NET Standard 支持的 .NET Framework 和 .NET Core
  • .net 按比例显示图片的缩略图
  • .NET 中 GetHashCode 的哈希值有多大概率会相同(哈希碰撞)
  • .NET开发人员必知的八个网站
  • .ui文件相关