Time of Update: 2018-12-05
C# 擷取路徑string str1 =Process.GetCurrentProcess().MainModule.FileName;//獲得當前執行的exe的檔案名稱。string str2=Environment.CurrentDirectory;//擷取和設定目前的目錄的完全限定路徑。string str3=Directory.GetCurrentDirectory();//擷取應用程式的當前工作目錄。string
Time of Update: 2018-12-05
轉自:壊壊—娚孩 反恐金鷹 winform擷取檔案路徑string str1 =Process.GetCurrentProcess().MainModule.FileName;//獲得當前執行的exe的檔案名稱。string str2=Environment.CurrentDirectory;//擷取和設定目前的目錄的完全限定路徑。string str3=Directory.GetCurrentDirectory();//擷取應用程式的當前工作目錄。string
Time of Update: 2018-12-05
--DateTime 數字型System.DateTime currentTime=new System.DateTime();1.1 取當前年月日時分秒currentTime=System.DateTime.Now;1.2 取當前年int 年=currentTime.Year;1.3 取當前月int 月=currentTime.Month;1.4 取當前日int 日=currentTime.Day;1.5 取當前時int 時=currentTime.Hour;1.6 取當前分int
Time of Update: 2018-12-05
1、#define宏定義,在編譯前由前置處理器對代碼作字串的替換。宏定義不是語句,後面不加“;”。2、typedeftypedef是在編譯時間處理的,在自己的範圍內給一個已經存在的類型一個別名 3、例: typedef int * int_ptr; 與 #define int_ptr int * 作用都是用int_ptr代表 int * ,但是二者不同,正如前面所說 ,#define在預先處理 時進行簡單的替換,而typedef不是簡單替換
Time of Update: 2018-12-05
private void BindTreeView() { UnitInfo bUnitInfo = new UnitInfo(); DataSet ds = bUnitInfo.GetUnitInfo(); if (ds != null && ds.Tables[0].Rows.Count > 0) { bool HasAddedLast = true; ;
Time of Update: 2018-12-05
using System;namespace BinaryTree{ // Binary Tree的結點類 class Node { public int Data { get; set; } public Node LeftSubNode { get; set; } public Node RightSubNode { get; set; } // 結點為自己追加子結點(與向左/向右追加結點,形成遞迴)
Time of Update: 2018-12-05
無限迴圈有兩種常用的方法:while(1) 和 for(; ; ) 。兩種方法的效果一樣,相比之下,哪種更好些?編譯後代碼對比:1、while( 1 );00401028 mov eax,10040102D test eax,eax0040102F je main+23h (00401033)00401031 jmp main+18h (00401028) 2、for( ; ; );00401033 jmp main+23h (00401033)對比發現,for(;
Time of Update: 2018-12-05
虛函數:把一個基類函式宣告為virtual,概函數就可以在任何衍生類別中重寫了。class MyBaseClass{ public virtual string VirtualMethod() {return "This method is virtual and defined in
Time of Update: 2018-12-05
C#打包應用程式(卸載程式)1:卸載【續】關於"卸載"功能的添加上面的文章只介紹了簡單的產生安裝的方法,但是在vs.net2005下並沒有直接產生卸載程式的功能,所以我們只好用msi來實現了,原理我就不講了,網上一搜一堆,我只講操作,【1】:在添加你的應用程式項目的時候,多添加一個msiexec.exe進去,這個檔案在c:windowssystem32檔案夾下,添加進去以後,為了讓他更像個卸載程式,把他的名字改成"Uninstall.exe",當然這個關係不大,改不改都行的.然後給他建立一個捷徑
Time of Update: 2018-12-05
1、DateTime 數字型 System.DateTime currentTime=new System.DateTime(); 1.1 取當前年月日時分秒 currentTime=System.DateTime.Now; 1.2 取當前年 int 年=currentTime.Year; 1.3 取當前月 int 月=currentTime.Month; 1.4 取當前日 int 日=currentTime.Day; 1.5 取當前時 int 時=currentTime.Hour; 1.6
Time of Update: 2018-12-05
/// <summary> /// C#中擷取CheckListBox選中項的值。 /// </summary> /// <param name="clb">要被擷取選中項的CheckListBox類型的對象。</param> /// <returns>返回一個ArrayList類型的對象。</returns> private
Time of Update: 2018-12-05
ADO.NET操作資料代碼匯總(C#)一.用SqlConnection串連SQL Server1..加入命名空間using System.Data.SqlClient;2.串連資料庫SqlConnection myConnection = new SqlConnection();myConnection.ConnectionString = "user id=sa;password=sinofindb;initial catalog=test;data
Time of Update: 2018-12-05
c#中擷取顏色的argb值:顏色有4個要素, A(Alpha,透明度),R(Red,紅色成分),G(Green,綠色成分),B(Blue,藍色成分),都是byte類型的,把他們合到一個Int32中就可以了. 舉例: int mycolor; Color c = Color.Red; //自己設定想要的某個顏色。mycolor = c.A * 256 *256 * 256 + c.R * 256 * 256 +
Time of Update: 2018-12-05
很多時候我們需要用到滑鼠在相對於表單上的座標,或者相對於螢幕的座標,這裡就把我的經驗記錄下。 用Control.MousePosition獲得當前滑鼠的座標CurrentPoint,使用Control.PointToClient方法,前面獲得的CurrentPoint作為其參數,返回的Point類型的對象即為滑鼠相對於某個控制項的座標。現在以滑鼠相對於表單的座標做為例子,如下: Point screenPoint =
Time of Update: 2018-12-05
// 數字二,八,十,十六進位轉成字串Convert.ToString(要轉的數, 進位);例子: string strResult;strResult = Convert.ToString(253, 2);// 結果:strResult=11111101 strResult = Convert.ToString(253, 8);// 結果:strResult=375 strResult = Convert.ToString(253, 10);// 結果:strResult=253
Time of Update: 2018-12-05
static void Main(string[] args) { Console.WriteLine("請輸入第一個字串"); string str1 = Console.ReadLine(); Console.WriteLine("請輸入第二個字串"); string str2= Console.ReadLine(); foreach
Time of Update: 2018-12-05
一、label太短,無法完成顯示所要顯示資訊長度,要換行,解決方案如下:(1)string aa =(長串) ; string cc= aa.Substring(0,10);//取前10個字元 string dd=aa.Substring(11);取後邊的 Label.Text=cc.Trim() + "\n"(換行)
Time of Update: 2018-12-05
1.建立一個C# windows應用程式2.添加一個windows表單Label到Form1.cs3.單擊label1控制項然後更改Text屬性為空白字元4.更改BorderStyle屬性為FixedSingle5.按右鍵Form1.cs,然後點擊View Code添加下面Using語句到Form1.cs源碼的頂部6.using System.Runtime.InteropServices;注意該步驟添加必要的引用來調用InteropServices函數和方法7.private Bitmap
Time of Update: 2018-12-05
C#如何擷取滑鼠相對當前視窗的座標 可以用Control.MousePosition獲得當前滑鼠的座標,使用PointToClient計算滑鼠相對於某個控制項的座標,如下 Point screenPoint = Control.MousePosition;//滑鼠相對於螢幕左上方的座標 Point formPoint = this.PointToClient(Control.MousePosition);//滑鼠相對於表單左上方的座標 Point contextMenuPoint =
Time of Update: 2018-12-05
在用線程的時候,如果線程要對控制項進行操作,那麼在表單初始化的時候要加上這句: System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; 具體資訊MSDN上有詳細的說明。另外,在退出程式的時候如果自訂線程還在操作控制項,那麼在退出程式之前一定要先把自訂線程給終止(Thread.Abor()方法),否則會拋出System.InvalidOperationException異常:{"執行