在使用QQ的截圖功能的時候,是不是覺得它的遊標很酷呢?今天就來談談怎麼應用自訂遊標,在我們的截圖工具中使用QQ截圖的遊標。
#所需遊標檔案下載 :C#軟體開發實例.私人訂位自己的螢幕截圖工具中使用的遊標檔案
#region 自定义光标 System.Windows.Forms.Cursor cursorCross = null; System.Windows.Forms.Cursor cursorDefault = null; System.Windows.Forms.Cursor cursorText = null; System.Windows.Forms.Cursor cursorColor = null; #endregion
[DllImport("user32.dll")] private static extern IntPtr LoadCursorFromFile(string fileName);
/// <summary> /// 从已有资源中获得光标 /// </summary> /// <param name="resource"></param> /// <returns></returns> public static Cursor getCursorFromResource(byte[] resource) { byte[] b = resource; FileStream fileStream = new FileStream("cursorData.dat", FileMode.Create); fileStream.Write(b, 0, b.Length); fileStream.Close(); Cursor cur = new Cursor(LoadCursorFromFile("cursorData.dat")); return cur; }
/// <summary> /// 窗口初始化事件处理程序 /// </summary> private void Form1_Init() { this.isCuting = false; this.beginPoint = new Point(0, 0); this.endPoint = new Point(0, 0); cursorDefault = getCursorFromResource(Properties.Resources.Cursor_Default); cursorCross = getCursorFromResource(Properties.Resources.Cursor_Cross); cursorText = getCursorFromResource(Properties.Resources.Cursor_Text); cursorColor = getCursorFromResource(Properties.Resources.Cursor_Color); }
else條件中新增:
this.Cursor = cursorDefault;在ExitCutImage方法中新增程式碼:
this.Cursor = cursorDefault;新增滑鼠進入Form1窗體事件處理程序:
/// <summary> /// 鼠标进入Form1窗体事件处理程序 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_MouseEnter(object sender, EventArgs e) { this.Cursor = cursorDefault; }Form1的
建構子中新增程式碼:
Form1_Init();Ok,編譯,截圖看看效果吧!
以上是C#開發實例-訂位螢幕截圖工具(九)使用自訂遊標和QQ截圖時的遊標(圖)的詳細內容。更多資訊請關注PHP中文網其他相關文章!