3

After browsing, I have a code to to control the movements of mouse programatically by giving the co-ordinates using C#. i want to do the same thing but mouse pointer should be replaced by a dot image. i'm not able to get it... so please let me know if there is any way in C#...

Advance Thanks:)

ragz
  • 99
  • 4
  • 14

1 Answers1

2

Here is a great tutorial that shows you how to do that.

UPDATE

As Hans Passant brought to my attention, there is a better approach. Here is his version, taken from this Stack Overflow Post:

using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;

static class NativeMethods {
    public static Cursor LoadCustomCursor(string path) {
        IntPtr hCurs = LoadCursorFromFile(path);
        if (hCurs == IntPtr.Zero) throw new Win32Exception();
        var curs = new Cursor(hCurs);
        // Note: force the cursor to own the handle so it gets released properly
        var fi = typeof(Cursor).GetField("ownHandle", BindingFlags.NonPublic | BindingFlags.Instance);
        fi.SetValue(curs, true);
        return curs;
    }
    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    private static extern IntPtr LoadCursorFromFile(string path);
}

And here is a usage example:

this.Cursor = NativeMethods.LoadCustomCursor(@"c:\windows\cursors\aero_busy.ani");

Good luck!!

Community
  • 1
  • 1
Matt Cashatt
  • 23,490
  • 28
  • 78
  • 111