===============================================================================================================

計算程式執行時間

 

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();//引用stopwatch物件

sw.Reset();//碼表歸零

sw.Start();//碼表開始計時

/**************/

/**************/

/***目標程式***/

/**************/

/**************/

sw.Stop();//碼錶停止

//印出所花費的總豪秒數

string sTime = sw.Elapsed.TotalMilliseconds.ToString(); 

==========================================================================
呼叫外部執行EXE檔案
 
using System.Diagnostics;
 
private void button1_Click(object sender, EventArgs e)
{
  ProcessStartInfo start=new ProcessStartInfo("外部路徑");
  start.WindowStyle = ProcessWindowStyle.Normal;
  Process.Start(start);
}

 

抓取目前應用程式路徑

string sCurrDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

==========================================================================

使用程式碼插入DataGridView欄位資料

 

image

private void button4_Click(object sender, EventArgs e)
{
     DataGridViewRowCollection rows = dataGridView1.Rows;
     rows.Add(new object[] { "A1", "2010/06/21", "09:22" });
     rows.Add(new object[] { "B1", "2011/06/21", "09:22" });
     rows.Add(new object[] { "C1", "2012/06/21", "09:22" });
     rows.Add(new object[] { "D1", "2013/06/21", "09:22" });
     rows.Add(new object[] { "E1", "2014/06/21", "09:22" });

}

目前dataGridView索引值

private void button5_Click(object sender, EventArgs e)
{
     int nCurIndex = dataGridView1.CurrentCell.RowIndex;
     label1.Text = nCurIndex.ToString();
}

==========================================================================

An INI file handling class using C#

image

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Ini;

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
     IniFile ini = new IniFile("C:\\test.ini");
     ini.IniWriteValue("Info","Name",name.Text);
     ini.IniWriteValue("Info","LastName",lname.Text);
}
private void Form1_Load(object sender, System.EventArgs e)
{
     IniFile ini = new IniFile("C:\\test.ini");
     name.Text= ini.IniReadValue("Info","Name");
     lname.Text = ini.IniReadValue("Info","LastName");
}

==========================================================================

檔案是否存在?

using System.IO;

private void button7_Click(object sender, EventArgs e)
{
     if (File.Exists("c:\\param.ini"))
         MessageBox.Show("檔案存在");
     else
         MessageBox.Show("檔案不存在");
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()