System.Diagnostics.Process.Start(@"C:\Program Files\Internet Explorer\IEXPLORE.EXE",@"http://www.baidu.com");
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName= "notepad.exe";
proc.Start();
proc.WaitForExit();
一..Net Framework
1.如何获得系统文件夹
使用System.Envioment类的GetFolderPath方法;例如:
Environment.GetFolderPath( Environment.SpecialFolder.Personal )
2.如何获得正在执行的exe文件的路径
1)使用Application类的ExecutablePath属性
2)System.Reflection.Assembly.GetExecutingAssembly().Location
3.如何检测操作系统的版本
使用Envioment的OSVersion属性,例如:
OperatingSystem os = Environment.OSVersion;
MessageBox.Show(os.Version.ToString());
MessageBox.Show(os.Platform.ToString());
4.如何根据完整的文件名获得文件的文件名部分、
使用System.IO.Path类的方法GetFileName或者GetFileNameWithoutExtension方法
5.如何通过文件的全名获得文件的扩展名
使用System.IO.Path.GetExtension静态方法
7.如何获得当前电脑用户名,是否联网,几个显示器,所在域,鼠标有几个键等信息
使用System.Windows.Forms. SystemInformation类的静态属性
8.修饰Main方法的[STAThread]特性有什么作用
标示当前程序使用单线程的方式运行
9.如何读取csv文件的内容
通过OdbcConnection可以创建一个链接到csv文件的链接,链接字符串的格式是:"Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq="+cvs文件的文件夹路径+" Extensions=asc,csv,tab,txt; Persist Security Info=False";
创建连接之后就可以使用DataAdapter等存取csv文件了。
10. 如何获得磁盘开销信息,代码片断如下,主要是调用kernel32.dll中的GetDiskFreeSpaceEx外部方法。
publicsealedclassDriveInfo
{
[DllImport("kernel32.dll",EntryPoint="GetDiskFreeSpaceExA")]
privatestaticexternlongGetDiskFreeSpaceEx(stringlpDirectoryName,
outlonglpFreeBytesAvailableToCaller,
outlonglpTotalNumberOfBytes,
outlonglpTotalNumberOfFreeBytes);
publicstaticlongGetInfo(stringdrive,outlongavailable,outlongtotal,outlongfree)
{
returnGetDiskFreeSpaceEx(drive,outavailable,outtotal,outfree);
}
publicstaticDriveInfoSystemGetInfo(stringdrive)
{
longresult,available,total,free;
result=GetDiskFreeSpaceEx(drive,outavailable,outtotal,outfree);
returnnewDriveInfoSystem(drive,result,available,total,free);
}
}
publicstructDriveInfoSystem
{
publicreadonlystringDrive;
publicreadonlylongResult;
publicreadonlylongAvailable;
publicreadonlylongTotal;
publicreadonlylongFree;
publicDriveInfoSystem(stringdrive,longresult,longavailable,longtotal,longfree)
{
this.Drive=drive;
this.Result=result;
this.Available=available;
this.Total=total;
this.Free=free;
}
}
可以通过
11.如何获得不区分大小写的子字符串的索引位置
1)通过将两个字符串转换成小写之后使用字符串的IndexOf方法:
stringstrParent="TheCodeprojectsiteisveryinformative.";
stringstrChild="codeproject";
//Thelinebelowwillreturn-1whenexpectedis4.
inti=strParent.IndexOf(strChild);
//Thelinebelowwillreturnproperindex
intj=strParent.ToLower().IndexOf(strChild.ToLower());
2)
usingSystem.Globalization;
stringstrParent="TheCodeprojectsiteisveryinformative.";
stringstrChild="codeproject";
//WecreateaobjectofCompareInfoclassforaneutralcultureoracultureinsensitiveobject
CompareInfoCompare=CultureInfo.InvariantCulture.CompareInfo;
inti=Compare.IndexOf(strParent,strChild,CompareOptions.IgnoreCase);
二
1. 什么是复制构造函数
我们知道构造函数是用来初始化我们要创建实例的特殊的方法。通常我们要将一个实例赋值给另外一个变量c#只是将引用赋值给了新的变量实质上是对同一个变量的引用,那么我们怎样才可以赋值的同时创建一个全新的变量而不只是对实例引用的赋值呢?我们可以使用复制构造函数。
我们可以为类创造一个只用一个类型为该类型的参数的构造函数,如:
publicStudent(Studentstudent)
{
this.name=student.name;
}
使用上面的构造函数我们就可以复制一份新的实例值,而非赋值同一引用的实例了。
classStudent
{
privatestringname;
publicStudent(stringname)
{
this.name=name;
}
publicStudent(Studentstudent)
{
this.name=student.name;
}
publicstringName
{
get
{
returnname;
}
set
{
name=value;
}
}
}
classFinal
{
staticvoidMain()
{
Studentstudent=newStudent("A");
StudentNewStudent=newStudent(student);
student.Name="B";
System.Console.WriteLine("Thenewstudent'snameis{0}",NewStudent.Name);
}
}
The new student's name is A.
2.什么是只读常量
就是静态的只读变量,它通常在静态构造函数中赋值。
classNumbers
{
publicreadonlyintm;
publicstaticreadonlyintn;
publicNumbers(intx)
{
m=x;
}
staticNumbers()
{
n=100;
}
}//其中n就是一个只读的常量,对于该类的所有实例他只有一种值,而m则根据实例不同而不同
三.VS.Net IDE
1. 2请看原作
3.如何改变region的颜色
通过工具 à 选项 à 环境 à 字体和颜色 à 可折叠文本设置
四.WinForm
1.如何使winForm不显示标题栏?
通过设置form的Text属性为空字符串,设置ControlBox属性为false
form1.Text = string. Empty;
form1.ControlBox = false;
2.如何使winform的窗体使用XP的风格
见原作
3.如何禁止form在工具栏显示
设置form的ShowInTaskbar属性为false即可
4.如何使程序打开默认的邮件程序并带有一些参数让用户开始写邮件
1)如果是web程序:
2) 对于windows程序,需要使用System.Diagnostics.Process类.如何创建类似msn提示窗口
Processprocess=newProcess();
process.StartInfo.FileName="mailto:email@address1.com,email@address2.com?subject=Hello&cc=email@address3.com
&bcc=email@address4.com&body=HappyNewYear";
process.Start();
5
需要获得通过Screen.GetWorkingArea(this).Width(Height)属性获得屏幕的大小,然后使用一个timer根据时间改变窗口的位置
五.Button控件
1.如何设置form的默认button(即在form上按下回车时触发的button)
可以设置form的AcceptButton属性:form1.AcceptButton = button1;
2. 如何设置form的取消button(即在用户按下Esc键时触发的button)
可以设置form的CancelButton属性:form1.CancelButton = buttonC;
3. 如何通过程序触发一个button的Click事件
Button1.PerformClick
六.Combo Box
1.如何使用可选字体填充Combo Box
comboBox1.Items.AddRange (FontFamily.Families);
七.TextBox
1.如何禁用TextBox的默认上下文菜单(右键菜单)
textBox1.ContextMenu = new ContextMenu();
2,3 见原作
4.如何在TextBox获得焦点的时候,将焦点放在textBox文字的最后
textBox1.SelectionStart = textBox1.Text.Length;
. OOPs一种更优雅的方法是使用System.Globalization命名空间下面的CompareInfo类的IndexOf方法:DriveInfoSystem info = DriveInfo.GetInfo("c:");来获得指定磁盘的开销情况
分享到:
相关推荐
打开网页C#源代码程序System.Diagnostics.Process.Start
最有用的牛B东东--System.Diagnostics.Process.Start()
调用和关闭指定的程序,C#源代码,System.Diagnostics.Process.Start("notepad.exe"); 用VisualStudio2008创建
用winform启动其他winform已经没有问题,并且可以在程序之间通讯传递值。 但是如果把启动命令放到windows services中来执行的话,第二个winform就不会打开,而是被当做后台程序执行。不知原因。...
Spawnr Spawnr是.NET Standard库,它使Process.Start变得简单。 它具有用于生成进程并将其输出作为React流使用的功能性API。
出错信息: 代码如下:Unknown error (0xffffffff)at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)at System.Diagnostics.Process.Start()at System.Diagnostics.Process.Start...
flvmdi,flv修复工具,针对ffgpeg+mencoder转化后的问题 ...System.Diagnostics.Process flvmdi = System.Diagnostics.Process.Start(flvmdiInfo); flvmdi.WaitForExit(); flvmdi.Close(); flvmdi.Dispose();
System.Diagnostics.Process.Start("cmd.exe", "/c netsh wlan start hostednetwork"); 停止代码: System.Diagnostics.Process.Start("cmd.exe", "/c netsh wlan stop hostednetwork"); 提示:SSID:输入网络的...
class test { static void Main() { //声明一个程序信息类 System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics....Proc = System.Diagnostics.Process.Start(Info); 剩余代码省略。。。。
DevExpress9.3.4汉化破解 开发电脑上直接运行Register.bat 客户电脑上很奇怪,连同DLL复制到客户端后,显示未... System.Diagnostics.Process.Start(startInfo); } 如果自动破解失败,也可以手工运行一下Register.bat
使用C#代码实现控制Windows系统关机...一般使用System.Diagnostics.Process.Start()方法来启动shutdown.exe程序。 下载下来是一个winform程序源码,包含说明,可使用按钮来执行关机,重启和注销。也可以是发命令方式。
程序是抓QQ主程序窗体句柄,通过移位定位到QQ 输入框,虚拟键盘输入后,ALT切换到密码框的方式实现的 光标移动到位,设置焦点。程序就不会落伍。2016版本在我机器上调试通过。
直接将网页生成高分辨率的PDF文件,... System.Diagnostics.Process p = System.Diagnostics.Process.Start(@"" + pdfCreater + "", @"" + htmlUrl + " " + pdfPath + ""); returnStr = "ok"; return returnStr; }
System.Diagnostics.Process.Start(openFileDialog1.FileName);//打开选择的文件 } Form1_Load(sender, e);//重新加载菜单 } private void Form1_Load(object sender, EventArgs e) { 文件ToolStripMenuItem...
源码提供,自动升级小程序,可以自动从指定目录下载(在updatelist.xml文件下Url指定),简单方便,实用。 调用也很简单,只需在你的主程序上... System.Diagnostics.Process.Start(sUpdateEXE);//启动更新程序 }
Spire.PDF软件给开发者提供了一种以C#编程的方式,在.NET平台上将PDF文件转换为word的功能. 下面是代码片段: 步骤1:创建一个新的PDF文件并加载...System.Diagnostics.Process.Start("图文版丽江旅游攻略大全.doc");
process = System.Diagnostics.Process.Start(this.exeName); // Wait for process to be created and enter idle condition process.WaitForInputIdle(); // Get the main handle appWin = process....
process = System.Diagnostics.Process.Start(this.exeName); process.WaitForInputIdle(); System.Threading.Thread.Sleep(150); appWin = process.MainWindowHandle; } catch (Exception ex) { ...
this.btn_9.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btn_9.ForeColor = System.Drawing.Color.Black; this....