摘要:///<summary>///取得某月的第一天///</summary>///<paramname="datetime">要取得月份第一天的时间</param>///<returns></returns>privateDateTimeFirstDayOfMonth(DateTimedatetime){returndatetime.AddDays(1-datetime.Day);}////<summary>///取得某月的最后一天///</summary>///<paramn
阅读全文
摘要:DataGridViewCellcell=this.dataGridView.CurrentCell;this.dataGridView.EndEdit();this.CurrentCell=null;
阅读全文
摘要:ComboBox绑定DataTabledt=newDataTabledt=//数据集this.DisplayMember=//要显示属性的字段this.DisplayMember.ValueMember=//要显示值的字this.comboBox.DataSource=dt;DataGridView禁止DataSource自动创建列this.DataGridView.AutoGenerateColumns = false;
阅读全文
摘要:C#查找指定文件夹下指定后缀名的所有文件,用递归的方法解决这类问题代码一:用ArrayList转化为string[]保存指定后缀名文件 最后Foreach循环输出或绑定usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingS
阅读全文
摘要:1 // 获取程序的基目录。2 System.AppDomain.CurrentDomain.BaseDirectory3 4 5 // 获取模块的完整路径。6 System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName7 8 9 // 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。10 System.Environment.CurrentDirectory11 12 13 // 获取应用程序的当前工作目录。14 System.IO.Directory.GetCurrentDirectory()15 16 1
阅读全文
摘要:几乎所有的大型应用都会有自己的用于跟踪调试的API。因为一旦程序被部署以后,就不太可能再利用专门的调试工具了。然而一个管理员可能需要有一套强大的日志系统来诊断和修复配置上的问题。Log4net是一款非常著名的记录日志开源组件,基本的框架源于另外的一个Java领域非常著名的姐妹组件-log4j。Log4net记录日志的功能非常强大。它可以将日志分不同的等级,比不同的样式,将日志输出到不同的媒介。现以一个实例说明Log4net的使用:1, 下载Log4net组件:http://logging.apache.org/log4net/download.htmlhttp://archive.apache
阅读全文
摘要:直接上代码 Bitmap bmp1 = new Bitmap(Application.StartupPath + "\\A.jpg"); Bitmap bmp2 = new Bitmap(Application.StartupPath + "\\B.jpg"); using (Graphics g = Graphics.FromImage(bmp1)) { Size size = new Size(bmp1.Width / 3, bmp1.Height / 3); Rectangle...
阅读全文
摘要:SoftReg类:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Management;namespaceSoftRegister{classSoftReg{///<summary>///获取硬盘卷标号///</summary>///<returns></returns>publicstringGetDiskVolumeSerialNumber(){ManagementClassmc=newManagementCla
阅读全文
摘要:1、添加一个定时器2、在定时器Tick事件里面写入下面代码 privatevoidtimer1_Tick(objectsender,EventArgse)//用Timer来控制滚动速度{label1.Left-=2;//设置label1左边缘与其容器的工作区左边缘之间的距离if(label1.Right<0)//当label1右边缘与其容器的工作区左边缘之间的距离小于0时{label1.Left=this.Width;//设置label1左边缘与其容器的工作区左边缘之间的距离为该窗体的宽度}}
阅读全文
摘要://获取图片的详细信息 并把图片转换到字节privatevoidbutton1_Click(objectsender,EventArgse){stringpPath=Application.StartupPath+@"\QQ.jpg";FileInfofi=newFileInfo(pPath);byte[]Temp=imageToByteArray(pPath);Imageimg=byteArrayToImage(Temp);intW=img.Width;intH=img.Height;stringFm=fi.Extension;//扩展名longsize=fi.Lengt
阅读全文
摘要:C# DUID用法Guid.NewGuid().ToString()的几种格式:1、Guid.NewGuid().ToString("N") 结果为: 38bddf48f43c48588e0d78761eaa1ce62、Guid.NewGuid().ToString("D") 结果为: 57d99d89-caab-482a-a0e9-a0a803eed3ba3、Guid.NewGuid().ToString("B") 结果为: {09f140d5-af72-44ba-a763-c861304b46f8}4、Guid.NewGuid()
阅读全文
摘要:DataGridView 给标题列增加序号代码privatevoiddataGridView1_DataBindingComplete(objectsender,DataGridViewBindingCompleteEventArgse){DataGridViewTextBoxColumndgv_Text=newDataGridViewTextBoxColumn();for(inti=0;i<dataGridView1.Rows.Count;i++){intj=i+1;dataGridView1.Rows[i].HeaderCell.Value=j.ToString();}}格式化某个字
阅读全文
摘要:DataGridView获取当前行代码int rows = this.dgv_Info.CurrentCell.RowIndex;//获取当前选中的行DataGridView获取当前选中行的某列值string code = this.dataGridView.CurrentRow.Cells["列名"].Value.ToString();窗体之间传值本次示例效果如下:Form1为父窗体(包含textBox1、button1)Form2为子窗体(包含textBox2、button2)父窗体给子窗体传值==================1.点击Form1的button1打开F
阅读全文
摘要:建一个产生验证码的核心类using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Drawing; using System.Drawing.Drawing2D; namespace BigHorseLib.Security { public class ValidCode { #region Private Fields private const double PI = 3.141592653589793...
阅读全文
摘要:记录一下截取字符串某位或移出某位移出字符串某位代码如下stringstr="5,6,7,8,9,";str=str.Remove(str.LastIndexOf(","),1);//这里是移出字符串最后一位是","的。截取字符串某位代码如下stringstr="110101198405167436";//获取身份证后四位intlength=str.Length-4;str=str.Substring(length,4);//length是获取从第几位开始截取,也可以如果想获取14之后的也可以直接写14(前提是18位
阅读全文
摘要:1.用正则表达式让文本框只能输入数字先导入 using System.Text.RegularExpressions;在文本框的KeyPress事件下加入一下代码第一种方法 if (!Char.IsNumber(e.KeyChar)) { e.Handled = true; }或者 if ((e.KeyChar >= '0' && e.KeyChar <= '9') || ((Keys)e.KeyChar == Keys.Back)) { e.Handled = fal...
阅读全文
摘要:下面代码是防止MDI子窗体多次实例化。//防止打开多个窗体 private bool ShowChildrenForm(string p_ChildrenFormText) { int i; //依次检测当前窗体的子窗体 for (i = 0; i < this.MdiChildren.Length; i++) { //判断当前子窗体的Text属性值是否与传入的字符串值相同 if (this.MdiChildren[i].Text == p_ChildrenFormText) { //如果值相同则表示此子窗体为想要调用的子窗体,激活此子窗体并返回true值 this.MdiChildre
阅读全文
摘要:两种通过第三方网站获取IP地址的方法第一种通过ip138网站获取 string strUrl = "http://www.ip138.com/ip2city.asp"; //获得IP的网址了 Uri uri = new Uri(strUrl); System.Net.WebRequest wr = System.Net.WebRequest.Create(uri); System.IO.Stream s = wr.GetResponse().GetResponseStream(); System.IO.StreamReader sr = new System.IO.Stre
阅读全文
摘要:IP地址、手机归属和身份证查询接口1. 查询手机:http://www.yodao.com/smartresult-xml/search.s?type=mobile&q=手机号码2. 查询IP:http://www.yodao.com/smartresult-xml/search.s?type=ip&q=IP地址3. 查询身份证:http://www.yodao.com/smartresult-xml/search.s?type=id&q=身份证号码返回一个XML文件,通过程序去解析就可以得到相应的信息下面是解析返回的代码 XmlDocument XmlDoc = ne
阅读全文
摘要:今天做东西遇到要给按钮添加快捷键。就在这介绍三种添加快捷键的方式。第一种Alt+*(按钮快捷键)在大家给button、label、menuStrip等控件设置Text属性时在名字后边加&键名就可以了,比如button1.text="确定(&A)"。就会有快捷键了,这时候按Alt+A就可以执行按钮单击事件。第二种Ctrl+*及其他组合键在WinForm中设置要使用组合键的窗体的KeyPreview(向窗体注册键盘事件)属性为True;然后使用窗体的KeyDown事件(在首次按下某个键时发生).实例代码:privatevoid窗体名字_KeyDown(objec
阅读全文