- 博客(35)
- 收藏
- 关注
原创 cefsharp的一些小操作
设置UA /// <summary> /// 初始化浏览器内核 /// </summary> private void InitCefBrowser() { if (!Cef.IsInitialized) { //设置UA CefSettings settings = new CefSett
2021-01-22 12:07:10 706
原创 wpf自定义控件路由事件写法
代码场景为一个自定义控件里面有个浏览器,将浏览器加载完成事件传到自定义控件CusNavigated事件中 /// <summary> /// 导航完成事件 /// </summary> public static readonly RoutedEvent NavigatedEvent = EventManager.RegisterRoutedEvent("CusNavigated", RoutingStrategy.
2021-01-22 11:59:09 267
原创 委托的用法实例
主窗体.csprotected void FormTitleChanged(string title){ this.Text = title;}private void button3_Click(object sender, EventArgs e){ Form3 f3 = new Form3(); f3.TitleChanged = new Form3.Ti...
2019-04-01 14:40:17 141
原创 WPF禁用输入框的复制、剪切、粘贴功能
<TextBox> <TextBox.CommandBindings> <CommandBinding Command="ApplicationCommands.Paste" CanExecute="CommandCanExecute"></CommandBinding> <CommandBinding
2019-02-25 10:55:09 2432
原创 c#Task多任务异步写法
private void GetAAA(){ //异步处理,FundRealRange为一个list,MaxDegreeOfParallelism为最大同时处理任务数. Parallel.ForEach(FundRealRange, new ParallelOptions { MaxDegreeOfParallelism = 10 }, (o) => { ...
2019-01-25 17:59:01 2225
原创 WPF datagrid鼠标右键获取行数据
private void RightClick(object sender, MouseButtonEventArgs e){ DataGrid g = sender as DataGrid; if (g.ContextMenu != null) { g.ContextMenuOpening += G_ContextMenuOpening; }...
2018-08-30 16:57:11 4062
原创 c# 打开word文件
引用Microsoft Office 14.0 Object LibraryMicrosoft Word 14.0 Object Library using MSWord = Microsoft.Office.Interop.Word; 定义private MSWord.Application m_word;private MSWord.Document m_doc; 事件 ...
2018-05-16 16:40:59 10708
原创 点击panel移动窗体
//移动窗体参数 bool beginMove = false; int currentXPosition; int currentYPosition; private void panel_up_button_MouseDown(object sender, MouseEventArgs e) {
2018-03-05 10:57:55 1290
原创 c#主线程外面的子线程中实现控制界面
用于解决线程间操作无效,从不是创建控件的线程访问它winform:this.Invoke(new Action(() =>{ textbox1 = "123"; })); wpf VM层:System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>{ Re...
2017-01-09 14:00:17 874
原创 datatable的一些小技巧
//搜索行var row = CodeData.Rows.OfType().Where(t => t.Field("名称") == code).ToList();//设置主键CodeData.PrimaryKey = new DataColumn[] { CodeData.Columns["名称"] };//设置主键
2017-01-03 11:33:38 230
原创 winform弹窗添加后传值
主窗体:AddCodeForm ACForm = new AddCodeForm();if (ACForm.ShowDialog() == DialogResult.OK){ string code = ""; ACForm.GetCode(ref code);}弹窗窗体:public void GetCode(ref string code){
2016-10-10 14:37:12 596
转载 C#获取本机IPv4和IPv6地址
这个要引入命名空间using System.Net;using System.Net.Sockets;因为AddressFamily枚举类型在这个命名空间中。public static string GetLocalIP() { try { string HostName = Dns.GetHostName(); //得到主机名 IPHostEntry
2016-06-21 10:19:33 5767 2
原创 c#复制文件夹(复制主文件夹和不复制主文件夹)
复制主文件夹 private void CopyDirectory(string srcdir, string desdir) { try { if (File.Exists(srcdir)) { File.Copy(srcdi
2016-05-09 11:33:23 695
原创 c#用rar压缩文件
string startpath = "E:\\send\\one\\234"; string endpath = "E:\\savefile\\456.rar"; System.Diagnostics.Process pro = new System.Diagnostics.Process(); pro.StartInfo.
2016-04-27 14:57:10 403
原创 winform的一些小技巧
//进程延迟System.Threading.Thread.Sleep(1010);//确认对话框DialogResult clo = MessageBox.Show("是否确定XXXXXXX", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);if (clo == DialogResult.Yes){///}
2015-07-24 15:05:16 372
原创 datagridview的一些小技巧
//滚轮定位到选中行dataGridView1.Rows[i].Cells["Column1"].Selected = true;dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows[i].Index;//清空选择dataGridView1.ClearSelection();//添加一行i
2015-07-24 13:52:29 594
转载 datagridview显示行号
添加datagridview的RowPostPaint事件。private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { var grid = sender as DataGridView; var row
2015-06-12 14:02:00 390
原创 c#查找相应目录下文件
string[] files = Directory.GetFiles(path, filename, System.IO.SearchOption.AllDirectories);
2015-05-18 15:22:58 1456
转载 c#打开对话框选择后输出文件路径文件名
// 获取文件夹绝对路径 显示在 txtbox 控件里System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();if (folder.ShowDialog() == DialogResult.OK){ textBox1.Text = folde
2015-05-18 13:52:31 4337
转载 winform中DataGridView导出到Excel
private void DataGridViewToExcel(DataGridView dgv) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Execl files (*.xls)|*.xls"; dlg.CheckFileExist
2015-02-25 10:38:44 266
原创 c#读取excel
System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog(); if (fd.ShowDialog() == DialogResult.OK) { string strConn = "Provider=Microsoft.A
2015-02-11 15:35:20 290
原创 c#发送邮件
System.Net.Mail.SmtpClient client = new SmtpClient("smtp.163.com"); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential("***@163.com",
2015-02-03 15:08:42 232
原创 c#数据存入文件通用函数
private void writelog(String str) { FileStream logFile; try { string logStr = Directory.GetCurrentDirectory() + "\\log.txt";
2015-01-16 14:17:18 355
原创 xml的读取
现在有以下数据库连接信息的xml文件: PC201310131126 sa 123456 Test 读取xml文件的数据库信息: XmlDocument doc = new XmlDocument(); doc.Load("sqlserver.xml");
2015-01-14 16:04:26 199
原创 c#截取未知长度的字符串前面字符到数字为止
private string Name(string strcode) { StringBuilder sb = new StringBuilder(); foreach (char var in strcode) { if (char.IsNumber(var))
2014-12-08 15:33:29 995
原创 c#连接数据库,执行存储过程
SqlConnection sqlCon = new SqlConnection("server=.;uid=ds;pwd=ds;database=库名"); SqlCommand sqlCmd = new SqlCommand("存储过程名",sqlCon); sqlCmd.CommandType=CommandType.StoredProcedu
2014-12-08 15:28:59 686
转载 c#中栈的定义、操作
class Stack { int maxsize; //顺序栈的容量 object[] data; //数组,用于存储栈中的数据 int top; //指示栈顶 public object this[int index]
2014-11-05 09:49:58 2082
转载 c#中Split用法
1、用字符串分隔: using System.Text.RegularExpressions;string str="aaajsbbbjsccc";string[] sArray=Regex.Split(str,"js",RegexOptions.IgnoreCase);foreach (string i in sArray) Response.Write(i.ToString()
2014-11-02 23:00:34 291
转载 C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
方法一:Convert.ToDateTime(string)string格式有要求,必须是yyyy-MM-dd hh:mm:ss================================================方法二:Convert.ToDateTime(string, IFormatProvider)DateTime dt;DateTimeFormatInfo
2014-10-28 15:59:14 467
转载 如何快速合并多个excel文件?包括.xls .csv格式
相信大家都有过面对几十个甚至上百个excel文件,不知道该如何快速合并到一起的问题吧?如果文件数量较少的话,还可以人工复制粘贴来解决,但是如果文件数量庞大,就不那么容易了。下面我介绍一种非常简单、高速的方法,自制合并小程序来解决这一问题。
2014-10-28 15:49:20 3683
原创 c#的 UDP接收
public partial class Form1 : Form { public Form1() { InitializeComponent(); Thread thread1 = new Thread(new ThreadStart(ReceiveData));
2014-09-02 09:35:26 528
原创 结构的定义,赋值,取值写法
public struct Market { public string WareName; public double NewPrice; public double BuyPrice1; public double SalePrice1; public str
2014-09-01 11:55:02 525
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人