C# 全域鍵盤鉤子 (Global Keyboard Hook) 完整實作:截獲熱鍵、防毒軟體偵測與應對
為什麼需要全域鉤子? 應用程式需在**無焦點、最小化、背景執行**時仍能接收特定熱鍵 (如 `Ctrl+Alt+A` 截圖)。表單層級 `KeyDown` 事件
C# XmlDocument 轉字串:MemoryStream + XmlTextWriter 完整實作與 XmlDocument.OuterXml 簡易替代
標準序列化實作 (可控制縮排、編碼) public static string XmlDocumentToString(XmlDocument xmlDoc,
C# XmlDocument 依節點名稱與值刪除特定子節點完整實作
核心邏輯 載入 XML → 找到父節點 → 遍歷子節點 → 比對 Name 與 Value → 移除符合節點 → 儲存。 實作代碼 = 0; i--)
C# 修正中文亂碼的 HttpWebRequest POST XML 進階實作:UTF-8 編碼、自動解壓、連線池管理
完整健壯實作 public static XmlDocument PostXmlTransaction(string url, XmlDocument xmlD
C# XML 檔案轉 DataSet:XmlDocument + XmlTextReader 完整實作
核心方法 public static DataSet ConvertXmlFileToDataSet(string xmlFilePath) { if
C# 取得應用程式安裝目錄下檔案路徑:HttpContext 與 AppDomain 兩種情境
Web 應用程式 (ASP.NET):HttpContext.Current.Request.PhysicalApplicationPath public st
C# DataTable RowFilter 過濾語法完整指南:條件組合、空值處理、效能與陷阱
基本語法 DataView view = dataTable.DefaultView; view.RowFilter = ColumnName = Value;
C# 比較字串格式日期大小:DateTime.Parse 直接比較
最簡單做法 DateTime.Parse(endTime)) { Console.WriteLine(開始時間晚於結束時間,邏輯錯誤); } 進階:
C# HttpWebRequest POST 發送 XML 完整實作:編碼處理、串流寫入、回應讀取
核心實作:標準 POST XML public string PostXml(string url, string xmlContent) { if (
C# XML 檔案轉字串:InnerXml vs OuterXml 差異與 XmlDocument.Load 完整用法
兩種載入方式比較 屬性/方法回傳內容包含根元素適用場景 XmlDocument.InnerXml根元素內部的 XML 字串否只需子樹內容、拼接到其他 XML
C# 使用 Regex 從字串提取數字:單一數字 vs 連續數字群組
核心方法:Regex.Matches using System.Text.RegularExpressions; public IEnumerable Ext
C# DevExpress GridView 依欄位值設定焦點列 (FocusedRowHandle) 實作
情境 在 DevExpress GridView 中,根據特定欄位的值 (如 ID、代碼) 找到對應列並設為焦點列 (高亮、捲動至可視區)。 基本實作 usi
C# 使用 Microsoft Office Interop Word 自動化處理文件:開啟、書籤替換、儲存完整範例
前置需求 安裝 Microsoft Office (含 Word) 或至少 Word 獨立安裝。 專案參考 Microsoft.Office.Interop.
C# WinForms 讓 Panel 內按鈕水平置中對齊的正確做法
問題現象 在 Panel (或 FlowLayoutPanel/TableLayoutPanel) 內放置多個 Button,預設靠左對齊。調整 Anchor、
C# 金額字串格式化與物件轉 Double 通用工具方法
金額格式化:依精度產生千分位字串 /// /// 將數值格式化為千分位、指定小數位數的字串 /// public static string FormatM
C# 判斷字串是否為數字:double.TryParse 完整用法與 NumberStyles 解析
標準做法:double.TryParse public static bool IsNumeric(string input) { if (string
C# 自訂數值格式字串 ToString("###,###,##0.00") 完整教學與金額格式化實作
自訂數值格式規格字元 規格名稱說明範例 (1234.5) 0零佔位符有數字顯示數字,無則顯示 00000.00 → 1234.50 #數字佔位符有數字顯示數
C# DataRow.ItemArray 屬性完整解析:批次存取、效能與原始碼實現
屬性定義 public object[] ItemArray { get; set; } 以 物件陣列 形式一次性取得或設定該列所有欄位值。索引順序對應 Dat