發表文章

目前顯示的是有「電腦-C#」標籤的文章

[C#]好用的WaitDialog

簡單的 Threading Wait Dialog

[C#] Caesar Cipher凱薩編碼加強版

支援自訂密碼書,包含數字、符號,也可以亂數排列增加複雜度。 支援預先定義key. Using: using System; using System.Text; using System.Security.Cryptography; using System.IO; using System.Linq; public static class CeasarCipher { // Default Key private const int Key = 3; // To increase the complexity of the ceaser cipher lower case"a-z", Numerics and Symbols also can be used private const string alphabets = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; private static char cipher(char c, int key) { int indexOfChar = alphabets.IndexOf(c); return (indexOfChar < 0) ? c : alphabets[(indexOfChar + key) % alphabets.Length]; } public static string Encipher(string input, int key = Key) { string output = string.Empty; foreach (char c in input) { if (c == ' ' || c == '\n') // keep white space / new line { ...

[C#]Caesar Cipher with customized base, including Numerics and Symbols

Support customized base string array, can be random order to increase complexity. Support pre-defined key. Using: using System; using System.Text; using System.Security.Cryptography; using System.IO; using System.Linq; public static class CeasarCipher { // Default Key private const int Key = 3; // To increase the complexity of the ceaser cipher lower case"a-z", Numerics and Symbols also can be used private const string alphabets = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; private static char cipher(char c, int key) { int indexOfChar = alphabets.IndexOf(c); return (indexOfChar < 0) ? c : alphabets[(indexOfChar + key) % alphabets.Length]; } public static string Encipher(string input, int key = Key) { string output = string.Empty; foreach (char c in input) { if (c == ' ' || c == '\n') // ...

[C#] 把DLL內崁在主程式中(DLL or EXE)

圖片
將要內崁的DLL加入至Visual Studio裡,並將建置動作改成 Embedded Resource 並且加入參考,Copy Local(複製到本機) = false 在 Program.cs 的 Main() 中,讓程式一開始就訂閱解析方式 AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; 並加入訂閱的function private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { string resourceName = "YourNameSpace." + new AssemblyName(args.Name).Name + ".dll"; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { byte[] assemblyData = new byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return Assembly.Load(assemblyData); } } 當應用程式執行時找不到相依組件時,就會依上述程式碼載入組件 相關系列文章:

[C#] 跨執行續更新UI

通常在開發winForm程式時,最容易碰到執行緒(thread)問題,而控制項(controls)的跨續問題也十分讓人頭痛,而通常出現的錯誤訊息,莫過於「跨執行緒作業無效: 存取控制項 ... 時所使用的執行緒與建立控制項的執行緒不同」。 通常在開發winForm程式時,最容易碰到執行緒(thread)問題,而控制項(controls)的跨續問題也十分讓人頭痛,而通常出現的錯誤訊息,莫過於「 跨執行緒作業無效: 存取控制項 ... 時所使用的執行緒與建立控制項的執行緒不同 」。 因為控制項( control )主要是存在 UI Thread (通常是 Main Thread )內,所以在非相同執行緒下要更新UI就會產生跨執行緒的錯誤。而一般常見的解法是用 delegate 搭配 Invoke ,缺點是不夠彈性,並且有時可能會不如預期的還是會發生跨執行序錯誤。google關鍵字「C# dalegate invoke」會找到很多類似例子。 然後我們從MSDN中 How to: Make Thread-Safe Calls to Windows Forms Controls 這篇文章中可以看到很多相關寫法,其中強調是 thread-safe 寫法的關鍵字在 Controls.InvokeRequired 。 MSDN上對這個值的說明「這個值會指示是否由於呼叫端是在建立控制項之執行緒以外的執行緒,因此在進行控制項的方法呼叫時,應呼叫叫用 (Invoke) 方法。」 而為了更有效便利的使用 Invoke 跟 InvokeRequired 去執行跨執行緒控制項操作,我通常會把這個方法撰寫class的擴充方法,並且加入 MethodInvoker 委派/ lambda 的應用。 使用方法與程式碼如下 public class main { //參考用controls TextBox tb = new TextBox(); void Func() { //使用lambda tb.InvokeIfRequired(() => { tb.Text = "hello"; }); //使用Act...

簡單的Debug Windows service方式

Debugging C# Windows Services the easy way http://www.ilove-it.com/post/2017/10/17/debugging-c-windows-services-the-easy-way 相關系列文章:

好用的 auto update library

https://github.com/ProgTrade/nUpdate

[C#] 讀取寫入EXCEL樣板範例 - 使用Interop.Excel

筆記用C#操作Excel的樣板

[C#] EXCEL 公式操作

用C#操作EXCEL公式的一些心得 Formula / FormulaR1C1 範例 R1C1運用 字串特殊字元處理(雙引號與反斜線)

[C#] 讓程式不顯示在工作管理員中

使用此方式讓程式不顯示在工作管理員中 可以避免程式遭使用者誤關閉