C#

C# 커서 바꾸기

outshine90 2014. 11. 12. 11:43

커서 바꾸기

    
static class NativeMethods
   {
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        private static extern IntPtr LoadCursorFromFile(string path);


        public static Cursor LoadCustomCursor(string path)
        {
            IntPtr hCurs = LoadCursorFromFile(path);
            if (hCurs == IntPtr.Zero) throw new Win32Exception();
            Cursor curs = new Cursor(hCurs);

            FieldInfo fi = typeof(Cursor).GetField("ownHandle", BindingFlags.NonPublic | BindingFlags.Instance);
            fi.SetValue(curs, true);
            return curs;
        }
    }


사용법은 
 
Cursors.Current = NativeMethods.LoadCustomCursor("MyCursor.cur");


이렇게 사용하면 흑백 커서말고도 사용가능