IO File.copy 实现文件的复制
摘要:如图:代码如下:View Code stringpath=@"c:\temp\MyTest.txt";stringpathCopy=@"c:\temp\MyTestCopy.txt";if(File.Exists(path)){File.Copy(path,pathCopy,true);File.Delete(path);}
阅读全文
posted @
2011-07-31 01:09
wtq
阅读(477)
推荐(0) 编辑
IO 使用File创建文本 streamwrite 写入字符,streamread输出字符
摘要:1.利用File.CreateText()来创建文本文件。代码如下:代码如下:View Code staticvoidMain(string[]args){stringpath=@"c:\temp\MyTest.txt";if(!File.Exists(path)){try{using(StreamWritersw=File.CreateText(path)){sw.WriteLine("thisismyname");sw.WriteLine("whataboutyou");sw.Write("?Ifine");}
阅读全文
posted @
2011-07-31 00:59
wtq
阅读(396)
推荐(0) 编辑
IO 使用readKey即时显示数据到控制台
摘要:View Code staticvoidMain(string[]args){ConsoleKeyInfoc=newConsoleKeyInfo();ConsoleKeyInfocki;do{cki=Console.ReadKey();if((cki.Modifiers&ConsoleModifiers.Control)!=0)Console.WriteLine("ctrl");if((cki.Modifiers&ConsoleModifiers.Alt)!=0)Console.WriteLine("alt");if((cki.Modif
阅读全文
posted @
2011-07-30 23:53
wtq
阅读(267)
推荐(0) 编辑
IO 使用try catch 自动错误跳转
摘要:1,以下代码显示被除0的错误提示代码如下:View Code staticvoidMain(string[]args){intaa=Console.In.Read();Console.Out.Write(aa);Console.ReadLine();inta=10;intb=0;try{intc=a/b;}catch(DivideByZeroExceptionexe){Console.WriteLine(exe.Message+""+"不能被整除");Console.WriteLine(exe.HelpLink);Console.WriteLine(ex
阅读全文
posted @
2011-07-30 22:52
wtq
阅读(366)
推荐(0) 编辑
linq 使用first筛选出第一条数据
摘要:View Code staticvoidMain(string[]args){List<Person>personL=newList<Person>();personL.Add(newPerson("wtq","男","13616009873",23));personL.Add(newPerson("wta","女","13616009871",24));personL.Add(newPerson("wtb","男&quo
阅读全文
posted @
2011-07-30 16:54
wtq
阅读(7855)
推荐(0) 编辑
LInq 使用where过滤,匿名类型来查找想要的数据。
摘要:View Code staticvoidMain(string[]args){List<Person>personL=newList<Person>();personL.Add(newPerson("wtq","男","13616009873",23));personL.Add(newPerson("wta","女","13616009871",24));personL.Add(newPerson("wtb","男&quo
阅读全文
posted @
2011-07-30 16:15
wtq
阅读(870)
推荐(1) 编辑
GDI+ 绘制多行文本
摘要:绘制多行文本,如图:思路主要设置drawstring的第二个参数的高度,这样就ok了。代码如下;View Code //privatevoidForm1_Paint(objectsender,PaintEventArgse)//{//Graphicsg=e.Graphics;//FontFamilyff=newFontFamily(GenericFontFamilies.Serif);//Fontf=newFont(ff,12,FontStyle.Italic|FontStyle.Bold|FontStyle.Strikeout|FontStyle.Underline);//stringst.
阅读全文
posted @
2011-07-30 01:21
wtq
阅读(814)
推荐(0) 编辑
GDI+ 绘制有边框的字体
摘要:绘制有边框的字体,如图思路,通过stringMessure来获取字体的长度。如下:View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;FontFamilyff=newFontFamily(GenericFontFamilies.Serif);Fontf=newFont(ff,12,FontStyle.Italic);stringstr="Height"+f.Height;//不添加而外的高度SizeFsf=g.MeasureString(str,f,int.M
阅读全文
posted @
2011-07-30 00:59
wtq
阅读(1375)
推荐(0) 编辑
GDI+ 使用窗体默认字体
摘要:下面将演示如何使用窗体的默认字体。 privatevoidForm1_Paint(objectsender,PaintEventArgse){FontFamilyff=newFontFamily(GenericFontFamilies.SansSerif);Fontf=newFont(ff,13,GraphicsUnit.Millimeter);Fontf1=newFont(ff,13,GraphicsUnit.Point);using(Fontf2=newFont(ff,23,FontStyle.Strikeout)){Graphicsg=e.Graphics;g.DrawString(&q
阅读全文
posted @
2011-07-29 23:58
wtq
阅读(476)
推荐(0) 编辑
GDI+ 钢笔和笔刷同时使用
摘要:可通过钢笔和笔刷混合 使用绘制出有边框的填充图案,如图:代码如下:View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;HatchBrushhb=newHatchBrush(HatchStyle.NarrowHorizontal,Color.Blue,Color.White);LinearGradientBrushlgb=newLinearGradientBrush(newPoint(2,2),newPoint(19,2),Color.Blue,Color.Brown);Penh.
阅读全文
posted @
2011-07-29 21:52
wtq
阅读(404)
推荐(1) 编辑
GDI+ 通过笔刷创建钢笔并绘制图案
摘要:先上图:提示:可通过笔刷来创建钢笔并绘制图形,以上是通过HatchBrush 来创建钢笔的。View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;HatchBrushhb=newHatchBrush(HatchStyle.NarrowHorizontal,Color.Red,Color.White);Penhp=newPen(hb,8);g.DrawRectangle(hp,12,12,200,200);hb.Dispose();}还可以通过LinearGridentBrush来.
阅读全文
posted @
2011-07-29 21:40
wtq
阅读(473)
推荐(0) 编辑
GGI+ 通过HatchBrush画刷来填充区域。
摘要:先上图:通过hatchbrush根据图案来填充,可通过HatchStyle枚举来设置图案。 代码如下:View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;HatchBrushhb=newHatchBrush(HatchStyle.OutlinedDiamond,Color.Red,Color.White);g.FillRectangle(hb,ClientRectangle);hb.Dispose();}
阅读全文
posted @
2011-07-29 20:51
wtq
阅读(345)
推荐(0) 编辑
GDI+ 绘制路径渐变图形
摘要:通过路径渐变画刷来绘制图片代码如下:View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;GraphicsPathgp=newGraphicsPath();Point[]p=newPoint[]{newPoint(10,10),newPoint(100,30),newPoint(50,100)};gp.AddLines(p);PathGradientBrushpgb=newPathGradientBrush(gp);pgb.CenterColor=Color.White;pgb..
阅读全文
posted @
2011-07-29 20:40
wtq
阅读(1564)
推荐(0) 编辑
linq where in 查询
摘要:在linq 中实现 sql 中的in查询时,可以使用如下语句:View Code ///intPropertySetId))();}Ls.ToList();<summary>///根据行业id获得属性集名///</summary>///<paramname="strPropertySetId"></param>///<returns></returns>publicList<string>GetHyNametByPromotionForWeb(List<int?>{if(intP
阅读全文
posted @
2011-07-29 14:38
wtq
阅读(5325)
推荐(0) 编辑
GDI+ Pen Brush
摘要:以下介绍pen的一些属性:1.画笔绘制方式Pen.Alignment 属性设置当钢笔的宽度超过1像素的时候,该如何绘制有Center,Inset ,Outset,Left,right。View Code Pena=newPen(Color.Tomato,20);a.Alignment=PenAlignment.Outset;g.DrawRectangle(a,50,50,100,100);2.定制短划线:View Code Pena=newPen(Color.Tomato,1);a.Alignment=PenAlignment.Outset;float[]f={15,5,10,2,30,10.
阅读全文
posted @
2011-07-28 15:40
wtq
阅读(491)
推荐(0) 编辑
GDI+ Point size
摘要:1,point 和size可以互相转换,如:View Code Pointp=newPoint(300,300);p.Offset(12,14);Sizes=newSize(12,12);p=(Point)s;//size转换为points=(Size)p;//point转换为size2.两个矩形的交集 Graphics g = e.Graphics; g.Clear(Color.White); Rectangle rr = new Rectangle(55,55,100,100); Rectangle r2 = new Rectangle(5,5,60,120); Rectangle r3.
阅读全文
posted @
2011-07-28 11:13
wtq
阅读(506)
推荐(1) 编辑
产生8位数的随机数
摘要:1:随机数的基数为大写字母26个,和数字0-9View Code namespacetest{classProgram{staticvoidMain(string[]args){stringresult=string.Empty;string[]arrString={"A","B","C","D","E","F","G","H","I","J","K","L"
阅读全文
posted @
2011-07-27 15:47
wtq
阅读(2456)
推荐(0) 编辑
正则表达式 每个单词首字母大写
摘要:usingSystem.Text.RegularExpressions;classRegExSample{staticstringCapText(Matchm){//Getthematchedstring.stringx=m.ToString();//Ifthefirstcharislowercase...if(char.IsLower(x[0])){//Capitalizeit.returnchar.ToUpper(x[0])+x.Substring(1,x.Length-1);}returnx;}staticvoidMain(){stringtext="fourscoreands
阅读全文
posted @
2011-07-27 11:39
wtq
阅读(4687)
推荐(0) 编辑
正则表达式 \b匹配
摘要:1,本文是参照http://www.cnblogs.com/deerchao/archive/2006/08/24/zhengzhe30fengzhongjiaocheng.html该连接地址而获得的见解。1 。在入门处。\b是正则表达式规定的一个特殊代码(好吧,某些人叫它元字符,metacharacter),代表着单词的开头或结尾,也就是单词的分界处。虽然通常英文的单词是由空格,标点符号或者换行来分隔的,但是\b并不匹配这些单词分隔字符中的任何一个,它只匹配一个位置。我编写的一个程序是: string pattern1 = @"\bhi\b.*\bLucy\b"; str
阅读全文
posted @
2011-07-26 17:39
wtq
阅读(12993)
推荐(0) 编辑
winform 实现打印功能
摘要:本文转自:http://www.cnblogs.com/freeliver54/archive/2010/10/20/1856978.html 学习c# winform 打印 参照了网络上诸多资源效果示意: 操作步骤:1、新建winform项目及创建窗体 2、拖取 打印 相关控件 PageSetupDialog 、 PrintDialog 、 PrintDocument 、PrintPreviewDialog 3、设置上述控件的Document属性为相应的PrintDocument 4、设置按钮等控件 及 添加相应按钮事件 5、示意代码如下 代码 publicpartialclassForm3
阅读全文
posted @
2011-07-26 11:44
wtq
阅读(35343)
推荐(3) 编辑
winform openFileDialog的使用。
摘要:代码如下:View Code 1privatevoidbtnOpenFileDialog_Click(objectsender,EventArgse)2{3OpenFileDialogoFD=newOpenFileDialog();4oFD.Title="打开文件";5oFD.ShowHelp=true;6oFD.Filter="文本文件|*.txt|RTF文件|*.rtf|所有文件|*.*";//过滤格式7oFD.FilterIndex=1;//格式索引8oFD.RestoreDirectory=false;9oFD.InitialDirectory=
阅读全文
posted @
2011-07-26 11:01
wtq
阅读(7848)
推荐(0) 编辑
winform筛选数据
摘要:文章引自:http://www.cnblogs.com/spgoal/archive/2006/09/04/494665.html代码如下:View Code stringInputStr=tbKey.Text;foreach(DataGridViewRowdvrindataGridView1.Rows){if(dvr.Cells[0].Value.ToString().StartsWith(InputStr)){dataGridView1.ClearSelection();dvr.Selected=true;dataGridView1.CurrentCell=dvr.Cells[1];bre
阅读全文
posted @
2011-07-25 17:12
wtq
阅读(600)
推荐(0) 编辑