C#连接EXCEL数据库
using System.Data.OleDb; //命名空间 private void button1_Click(object sender, EventArgs e) { string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.xls; Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn) string sql = "select * from [student$]"; //注意EXCEL数据库表形式 OleDbCommand cmd = new OleDbCommand(sql, conn); Ol...
C#跨线程调用
跨线程调用窗体控件 用户不喜欢反应慢的程序。在执行耗时较长的操作时,使用多线程是明智之举,它可以提高程序 UI 的响应速度,使得一切运行显得更为快速。在 Windows 中进行多线程编程曾经是 C++ 开发人员的专属特权,但是现在,可以使用所有兼容 Microsoft .NET 的语言来编写。不过Windows 窗体体系结构对线程使用制定了严格的规则。如果只是编写单线程应用程序,则没必要知道这些规则,这是因为单线程的代码不可能违反这些规则。然而,一旦采用多线程,就需要理解 Windows 窗体中最重要的一条线程规则:除...
c#获取系统内存等信息
//cpu频率using Microsoft.Win32;private int GetCPUFrequency() { RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"HARDWAREDESCRIPTIONSystemCentralProcessor"); object obj = rk.GetValue("~MHz"); int CPUFrequency = (int)obj; return CPUFrequency; }////////////////////////////////////磁盘空间 Managementusing System.Management;private long GetFreeDiskSpace() { ManagementObject disk = new Mana...
C#的Windows编程中多语言的实现
C#的Windows编程中多语言的实现作者:AspCool 属于c/c++分类 2010/9/9简介:这是C#的Windows编程中多语言的实现的详细页面,介绍了和c/c++,C#,#的,的W,Wi,in,nd,do,ow,ws,s编,编程,程中,中多,多语,语言,言的,的实有关的知识,加入收藏请按键盘ctrl+D,谢谢大家的观看!要查看更多有关信息,请点击此处 实现多语言的方法是通过配置文件实现,通过从配置文件中读取资源,然后在显示窗口的时候,即Load()方法中,动态显示相应的选择语言。 下面是在C#的Windows编程中实现多语言的步骤: 第...
C#读写XML
using System;using System.Collections.Generic;using System.Text;using System.IO;using System.Xml;namespace AutoRunMgr{ public class XML { public static void CreateNode(string xmlpath,string node,string value) { if (!File.Exists(xmlpath)) { XmlDocument xmlDoc = new XmlDocument(); XmlElement root = xmlDoc.CreateElement("setting"); XmlElement child = xmlDoc.CreateElement(node); ...
C#窗体淡入淡出
//淡入publicint state =0; privatevoid f2_Load(object sender, EventArgs e) { this.Opacity =0; } privatevoid timer1_Tick(object sender, EventArgs e) { if (state ==0) { this.Opacity +=0.02; if (this.Opacity ==1) { state =1; timer1.Enabled =false; } }else { this.Opacity = Opacity -0.02; if (this.Opacity ==0) { Application.ExitThread(); } } ...
C#获取软件图标
using System;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;using System.Runtime.InteropServices;using System.IO;namespace ShowIcon{ [StructLayout( LayoutKind.Sequential)] public struct FileInfomation { public IntPtr hIcon; public int iIcon; public int dwAttributes; [ MarshalAs( UnmanagedType.ByValTStr, SizeConst = 260 )] public str...
C#格式化数值结果表
C#格式化数值结果表字符说明示例输出C货币string.Format("{0:C3}", 2)$2.000D十进制string.Format("{0:D3}", 2)002E科学计数法1.20E+0011.20E+001G常规string.Format("{0:G}", 2)2N用分号隔开的数字string.Format("{0:N}", 250000)250,000.00X十六进制string.Format("{0:X000}", 12)C string.Format("{0:000.000}", 12.2)012.200StringsTher...
窗体间传值小结
windows form (窗体) 之间传值小结在windows form之间传值,我总结了有四个方法:全局变量、属性、窗体构造函数和delegate。第一个全局变量:这个最简单,只要把变量描述成static就可以了,在form2中直接引用form1的变量,代码如下:在form1中定义一个static变量public static int i= 9 ;Form2中的钮扣按钮如下:private void button1_Click(object sender, System.EventArgs e){ textBox1.Text = Form1.i.ToString();} 第二个方法是利用属性,请详见我的博客:http://blog.csdn.net/tjv...
C# 时间格式设置
C# 时间格式设置有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2005-6-6 14:33:34 如果要换成成200506,06-2005,2005-6-6或更多的该怎么办呢 我们要用到:DateTime.ToString的方法(String, IFormatProvider) using System; using System.Globalization; String format="D"; DateTime date=DataTime,Now; Response.Write(date.ToString(format, DateTimeFormatInfo.InvariantInfo)); 结果输出 Thursday, June 16, 2005 参数format格式详细用法 格式字符...