随笔分类 - C#
使用匿名类型做为ComboBox的DataSource
摘要:ArrayList list = new ArrayList(); list.Add(new { id = "0", value = "--请选择--" }); list.Add(new { id = "1", value = "一般案件" }); list.Add(new { id = "2", value = "银行案件" }); this.cboSource.DataSource = list; this.cboSource.ValueMember = "id
阅读全文
C#映射网路驱动器
摘要:using System.Runtime.InteropServices;using System.IO;using System.Text;class DriveReflection{ [StructLayout(LayoutKind.Sequential)] public class NetResource { public int dwScope; public int dwType; public int dwDisplayType; public int dwUsage; public string LocalName; public string RemoteName; publi
阅读全文
C#执行cmd
摘要:string cmdtext = "net use u: \\\\192.168.0.44\\src \"" + user + "\" /user:" + pwd; Process MyProcess = new Process(); //设定程序名 MyProcess.StartInfo.FileName = "cmd.exe"; //关闭Shell的使用 MyProcess.StartInfo.UseShellExecute = false; //重定向标准输入 MyProcess.StartInfo.Redi
阅读全文
C#读取sql脚本文件
摘要:/// <summary> ///读取sql脚本文件,注意:文件以utf-8格式保存 /// 每个执行单元,以独占一行的go结束 /// 可执行建表,修改表结构等操作 /// </summary> /// <param name="varFileName"></param> /// <returns></returns> public static List<string> SqlFileToList(string varFileName) { if (!File.Exists(varFil
阅读全文
asp.net 取得文件扩展名 C#
摘要:system.io.path下有好几个实用的方法. system.io.path.getExtension(path) 得到扩展名 system.io.path.getfilename(path)
阅读全文
asp.net点击下载图片 C#
摘要:DownloadFile.aspx页面内容:<%@ Page Language="C#" %><%//使用方法DownloadFile.aspx?file=要下载的图片 string url = HttpContext.Current.Request.Url.Query.ToLower(); //file=dddd.jpg url = url.Replace("?file=", ""); Response.BufferOutput = false; Response.Clear(); Response.Content
阅读全文
C# TextBox 换行 滚动到最后一行
摘要:1、要让一个Windows Form的TextBox显示多行文本就得把它的Multiline属性设置为true。这个大家都知道,可是当你要在代码中为Text属性设置多行文本的时候可能会遇到点麻烦:)你往往会想到直接付给一个含有换行符"\n"的字符串给Text属性:aTextBox.Text = "First Line\nSecond Line\nThird Line";可是实际运行的时候你却发现它始终不会换行,显示的结果为"First LineSecond LineThirdLine"。其实主要是因为TextBox运行在Windows
阅读全文
教你如何解决“线程间操作无效: 从不是创建控件的线程访问它” 转
摘要:在编程中经常会遇到在一个按钮中执行复杂操作,并将复杂操作最后返回的值加入一个ListView或ComboBox中候选。这个时候程序会卡,当程序员将这些卡代码放进线程(Thread)中后发现当对控件操作时出现“线程间操作无效: 从不是创建控件的线程访问它”异常。为什么.net不让我们跨线程操作控件,这是有好处的。因为如果你的线程多了,那么当两个线程同时尝试将一个控件变为自己需要的状态时,线程的死锁就会发生。但是难道就是因为这个原因,我们就只能让程序卡着么?当然不是,这里教大家一个解决方案:用BackGroundWorker这里通过一个实例来告诉大家BackGroundWorker的用法。首先我们
阅读全文
C# 退出程序时,强制结束线程
摘要:private void Form1_FormClosing(object sender, FormClosingEventArgs e) { System.Environment.Exit(System.Environment.ExitCode); Application.Exit(); }
阅读全文
asp.net获取当前网址url
摘要:设当前页完整地址是:http://www.jb51.net/aaa/bbb.aspx?id=5&name=kelli "http://"是协议名 "www.jb51.net"是域名 "aaa"是站点名 "bbb.aspx"是页面名(文件名) "id=5&name=kelli"是参数 【1】获取 完整url (协议名+域名+站点名+文件名+参数)代码如下:string url=Request.Url.ToString(); url= http://www.jb51.net/aaa/
阅读全文
aspx页面生成html
摘要:ToHtml.aspxprotected void Page_Load(object sender, EventArgs e) { //使用示例: //ToHtml.aspx?src=default.aspx 生成default.html //ToHtml.aspx?src=default.aspx?tag=index.html 生成index.html string source = Request.Params["src"]; string target = Request.Params["tag"]; if (target == null || t
阅读全文
模板替换
摘要:<htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>无标题页</title></head><body>标题:$title<br/>内容:$content</body></html>publicstaticstringWriteFileMethod(){stringpath=HttpContext.Current.Server.MapPath("test/");Encodingcode=Enc
阅读全文
泛型委托
摘要:public static void TraditionalDelegateSyntax() { List<int> list = new List<int>(); list.AddRange(new int[] { 1, 5, 10, 20, 33 }); Predicate<int> callback = new Predicate<int>(IsEvenNumber);//使用传统委托语法调用FindAll List<int> evenNumbers = list.FindAll(callback); foreach (int
阅读全文
解决“在证书存储区中找不到清单签名证书”
摘要:解决“在证书存储区中找不到清单签名证书”这个问题似乎以前碰到过,不过记不太清了。程序重新生成,提示错误:在证书存储区中找不到清单签名证书。可能是之前部署的程序证书被我删掉了或是证书过期了,结果出现这个问题。解决方案如下:方案1:右击项目属性—>签名—>为ClickOnce清单签名,将勾掉的选项去掉。方案2:在签名中创建一个新的签名。方案3:记事本打开相应的csproj文件,调整节点值。<SignManifests>true</SignManifests>将true修改为false。以上解决方案任选其一,我选了方案一,简单嘛。重新生成,问题搞定!
阅读全文
获得GridView模板列中控件所在行
摘要:protected void gvProList_RowCommand1(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "UpdateQty") { int orderDetailId = int.Parse(e.CommandArgument.ToString()); ImageButton btn = e.CommandSource as ImageButton; GridViewRow gvr = btn.NamingContainer as GridViewRow; //int r
阅读全文
Repeater分页显示最普通最使用的方法
摘要:Repeater分页显示 简单的说,就是先从控件工具箱中拖入两个label(currten page当前页,count page总页),四个linkbuttion(首/下页/上页/尾页)。 无非就是+1 -1 的问题, ------------------------ using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System
阅读全文
.NET连接池
摘要:ADO.Net 在数据库操作过程中默认打开了连接池,不需要再进行手工配置。这个特性可以使数据库操作时效率提高,但也要有相应的代码配合,才能真正提高程序效率。1、连接字符串 ADO.Net 中的连接池大小可以通过数据库连接字符串来控制,例如: string cs = "server=.;uid=sa;pwd=tcaccp;database=pubs;pooling=true;min pool size=5;max pool size=10" 其中 pooling 表示是否打开连接池,默认为打开,关掉时需要 pooling = false; min pool size 表示连接池最少保存几个连接对
阅读全文
C#模拟键盘鼠标事件 SendKeys 的特殊键代码表
摘要:C#模拟键盘鼠标事件SendKeys的特殊键代码表使用 SendKeys 将键击和组合键击发送到活动应用程序。此类无法实例化。若要发送一个键击给某个类并立即继续程序流,请使用 Send。若要等待键击启动的任何进程,请使用 SendWait。每个键都由一个或多个字符表示。若要指定单个键盘字符,请使用该字符本身。例如,若要表示字母 A,请将字符串“A”传递给方法。若要表示多个字符,请将各个附加字符追加到它之前的字符的后面。若要表示字母 A、B 和 C,请将参数指定为“ABC”。加号 (+)、插入符号 (^)、百分号 (
阅读全文
C# winform中listview 如何调整行高
摘要:首先向窗口内添加组件里的ImageList,然后将ListView的SmallImageList属性设置为刚才添加的ImageList,调整ImageList的高度就可以改变listview行高。
阅读全文
C#实现回车键代替Tab键
摘要:protected override bool ProcessCmdKey(ref Message msg, Keys keyData){if (keyData == Keys.Enter &&((!(ActiveControl is System.Windows.Forms.TextBox) ||!((System.Windows.Forms.TextBox)ActiveControl).AcceptsReturn))){SendKeys.SendWait("{Tab}");return true;}if (keyData == (Keys.Enter | Keys.Shift)){Send
阅读全文