随笔分类 -  C#(winform)

1
摘要:今天在调用excel.Application.Workbooks.Add(Missing.Value)时遇到如下错误: Exception: Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))这是Excel自身的一个bug,当本地系统环境被设置成非英文的,而Excel是英文的时候,就会出现,需要临时设定英文环境,代码如下:System.Globalization.CultureInfo CurrentCI = System.Threading.Thread.C 阅读全文
posted @ 2011-07-15 15:54 novel 阅读(781) 评论(0) 推荐(0)
摘要:最近用C#开发一个winform应用程序, 用户可以把数据导出到EXCEL,发布程序时发现不能调用office2002下的excel(开发环境是vs2005+office2003)在google搜索了下,有以下2个办法解决1 改变开发环境,使用客户使用的office版本.这样开发出来的程序可以兼容高版本 这是个老外的建议,我没有试过.http://www.eggheadcafe.com/ng/mi... 阅读全文
posted @ 2009-12-31 16:48 novel 阅读(1581) 评论(0) 推荐(0)
摘要:防止程序运行多个实例的方法有多种,如:通过使用互斥量和进程名等.而我想要实现的是:在程序运行多个实例时激活的是第一个实例,使其获得焦点,并在前端显示.主要用到两个API 函数:ShowWindowAsync 该函数设置由不同线程产生的窗口的显示状态。SetForegroundWindow 该函数将创建指定窗口的线程设置到前台,并且激活该窗口。键盘输入转向该窗口,并为用户改各种可视的记号。系统给创建... 阅读全文
posted @ 2009-12-08 11:20 novel 阅读(2173) 评论(1) 推荐(0)
摘要:做一个项目时,有个日期字段客户可输入可不输入值,直接把DateTime=Null时会出错,提示错误: 无法将 NULL 转换成"System.DateTime",因为它是一种值类型在网上查看下相关资料后,找到处理办法:Nullable<DateTime> now = DateTime.Now;Nullable<DateTime> now = null;当然也可以缩写:Da... 阅读全文
posted @ 2009-10-30 16:53 novel 阅读(4793) 评论(4) 推荐(2)
摘要:在Panel上加载一个窗体,类似MDI窗体,原以为像Delphi一样直接把form的parent设置为panel就可以实现.在写代码时没问题,运行时弹出error:Top-level control can not be added toa control(无法将顶级控件添加到控件),查看form的属性后发现要把TopLevel = false才能实现.最后的代码如下:private void S... 阅读全文
posted @ 2009-10-30 16:42 novel 阅读(2294) 评论(0) 推荐(0)
摘要:方法1:using System.IO;if (File.Exists("d:\a.exe")) { //do something }if (Directory.Exists("d:\abc\")) { //do something }方法2:DirectoryInfoaPath=newDirectoryInfo(PathName); if (aPath.Exists) { //do somet... 阅读全文
posted @ 2009-09-25 16:12 novel 阅读(364) 评论(0) 推荐(0)
摘要:昨天帮同事写了一个查找文件的小工具,却发现弹出了这个错误信息:The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 charact... 阅读全文
posted @ 2009-06-24 09:42 novel 阅读(2685) 评论(0) 推荐(0)
摘要:上个星期做一个复杂的报表导出到excel,发现每次导出后都有一个excel.exe进程.找到N久才找到的这段代码:#region Kill Special Excel Process[DllImport("user32.dll", SetLastError = true)]static extern int GetWindowThreadProcessId(IntPtr hWnd, out int... 阅读全文
posted @ 2009-06-15 14:19 novel 阅读(786) 评论(1) 推荐(0)
摘要:这几天在做一个导出数据到EXCEL的报表,某些数据值超过条件设置的需要用颜色表示出来.但导出Excel 只能用ColorIndex,不能用Color(我汗).在网上找到的这个图,不用自己去一个个试了. 阅读全文
posted @ 2009-06-04 10:58 novel 阅读(2282) 评论(0) 推荐(0)
摘要:XML:如下 1 user1 2 user2 问题: 1)[删除]1的记录并保存 2)[修改]]2记录的 为并保存 3)我要[添加]一个 3 ... 阅读全文
posted @ 2009-02-20 08:47 novel 阅读(629) 评论(0) 推荐(0)
摘要:Pen p = new Pen(Color.Black, 5); Graphics g = this.panelControl2.CreateGraphics(); //this.CreateGraphics(); //DrawArrow(g, p, 50, 20, 100, 20); p.DashSt... 阅读全文
posted @ 2009-01-02 08:43 novel 阅读(5737) 评论(4) 推荐(1)
摘要:DataTable dt = new DataTable(); dt.Columns.Add("id"); dt.Columns.Add("name"); dt.Rows.Add(new object[]{1, "aaa"}); dt.Rows.Add(new object[]{2, "bbb"}); dt.Rows... 阅读全文
posted @ 2008-12-31 08:32 novel 阅读(756) 评论(2) 推荐(0)
摘要:Code Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->private void view_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndic... 阅读全文
posted @ 2008-12-31 08:30 novel 阅读(710) 评论(0) 推荐(0)
摘要:可能的原因是:在你的项目中引用了第三方组件,并且这个第三方组件是个商业组件,他在组件的主使用类定义了LicenseProvider(typeof(LicFileLicenseProvider)) 这个Attribute。 VS2005在编译时检测到这个类的时候,会检查到组件使用的是LicFileLicenseProvider这个属性,表示有组件使用的是把... 阅读全文
posted @ 2008-12-31 08:28 novel 阅读(461) 评论(0) 推荐(0)
摘要:无法在证书存储区中找到清单签名证书 第一种办法:用记事本打开对应csproj文件。将 change " true " to "false". that's ok! 第二种办法: 在vs2005中出现“无法在证书存储区中找到清单签名证书”,解决办法是用记事本打开项目的.csproj文件,删除类似以下xml就能顺利通过编译了 B531F2CF222748C5E29308FC224770... 阅读全文
posted @ 2008-12-17 08:34 novel 阅读(346) 评论(0) 推荐(0)
摘要:1.读/写connectionStrings/appSettings Code Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->public static string GetConnectionStringsConfig(string connect... 阅读全文
posted @ 2008-12-16 16:42 novel 阅读(860) 评论(0) 推荐(0)
摘要:// 禁止用户改变DataGridView1的所有列的列宽 //DataGridView1.AllowUserToResizeColumns = false; //禁止用户改变DataGridView1の所有行的行高 dataGridView1.AllowUserToResizeRows = false; // 禁止用户改变列头的高度 dataGridView1.Co... 阅读全文
posted @ 2008-11-20 13:35 novel 阅读(1082) 评论(0) 推荐(0)
摘要:引用C:\Program Files\Microsoft Visual Studio 8\Common7\IDE 里面的Microsoft.Data.ConnectionUI.Dialog.dll。 using Microsoft.Data.ConnectionUI; DataConnectionDialog dialog = new DataConnectionDi... 阅读全文
posted @ 2008-11-20 13:31 novel 阅读(238) 评论(0) 推荐(0)
摘要:1、新建c#应用程序,将默认的From的IsMDIContainer设为True 2、另建一个From,名为FromView 3、声明一个私有变量:Private FromView FrmView1 4、写防止打开多个MDI窗口 if(FrmVIew1==null || FrmView1.IsDisposed) { FrmView1=new FormView(); FrmView1.MdiPare... 阅读全文
posted @ 2008-10-04 01:13 novel 阅读(489) 评论(0) 推荐(0)
摘要:原来一直是为每个文本框的KeyPress增加: if(e.KeyChar = '\r') SendKeys.Send("{TAB}"); 最近想想,其实有更简单的方法,把Form的KeyPreView设为true,然后在Form的KeyPress中增加下列代码即可: if (e.KeyChar == '\r') this.SelectNextCont... 阅读全文
posted @ 2008-10-03 23:10 novel 阅读(326) 评论(0) 推荐(0)

1