C#開發技巧

來源:互聯網
上載者:User

 

 

 

1、時間長度的計算 TimeSpan類。   

   例如:TimeSpan span = dateTime1 - dateTime2   方便啊

2、從類(Class)返回一個System.Type類型,用typeof關鍵字

3、從一個對象執行個體(Object)返回一個System.Type類型,用GetType方法

4、判斷是否處於設計狀態:DesignMode屬性

5、根據GUID建立對象執行個體

      System.Guid pGuid = new Guid(guid);

      System.Type ObjectCustorm = Type.GetTypeFromCLSID(pGuid);

      Object obj = Activator.CreateInstance(ObjectCustorm);

6、GDI+不支援xor繪製模式的近似解決方案: ControlPaint.DrawReversibleFrame、ControlPaint.DrawReversibleLine方法

7、擷取Enum類型中的所有枚舉值:  Enum.GetNames方法

  將字串轉換成枚舉值  Enum.Parse方法

8、Label放在圖片上時,使Label透明 picLogo.Controls.Add(lblStatus); lblStatus.BackColor = Color.Transparent;

9、調用協助檔案

   開啟協助檔案 Help.ShowHelp(this,@"c:/windows/help/mspaint.chm");

      開啟協助檔案,並跳轉到指定的主題 Help.ShowHelp(this,@"c:/windows/help/mspaint.chm","paint_lines.htm");

      開啟協助檔案,並轉到“索引”選項卡 Help.ShowHelpIndex(this,@"c:/windows/help/mspaint.chm","paint_lines.htm");

      在螢幕上顯示一條浮動的協助資訊 Help.ShowPopup(this,"這裡是協助資訊",new Point(100,100));

10、通過AppDomain在應用程式之間傳遞資料

   例如,兩個系統可能會共用登入資訊,登入一個系統後,再啟動另一個系統時,不需要重新登入。

   先定義一個在應用程式之間傳遞的資料的類,該類必須從MarshalByRefObject繼承:

 *  from table1 minux truncate table table1; insert into table1 select * from table_new;

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.