方法一:加載文件的方法(API), 推薦度:1級
2.1 添加引用 using System.Runtime.InteropServices;
2.2 在程序中聲明光標資源加載函數LoadCursorFromFile;
[DllImport("user32")]
private static extern IntPtr LoadCursorFromFile(string fileName);
2.3 聲明數組 byte[] cursorbuffer=namespace.Resource .CursorName;
Namespace為資源文件所在項目的命名空間名稱,CursorName對應光標資源文件名。
2.4 創建一個臨時光標文件tempTest.dat;將cursorbuffer中的數據寫入數據文件中;
FileStream fileStream = new FileStream("tempTest.dat", FileMode. Create);
fileStream.Write(cursorbuffer, 0, cursorbuffer.Length);
2.5 關閉文件,利用API 函數LoadCursorFromFile從光標臨時文件中創建光標。
fileStream.Close();
Cursor .Current =new Cursor(LoadCursorFromFile("temp001.dat"));
方法二:加載文件的方法,推薦度:1級
Cursor cursor = new Cursor(fileName);
方法三:使用資源文件,推薦度:5級
直接讀出字節數組,轉成流數據,
Cursor cursor = new Cursor(stream);
方法三:使用嵌入式資源文件,推薦度:5級
直接讀流數據,
Cursor cursor = new Cursor(stream);