0

I am using a PNG image as a cursor by translating the image with the mouse coordinates and it moves very nice. The problem is when I tried to click a button, for some reason the button flashes as I move the mouse over it. The button goes inactive or not focused and mouse clicks are not working until for some fraction of a second where if I keep moving the mouse and clicking over the button, then the mouse click works. I tried also to play with the z-index having no results.

When I tried the hidden cursor without the image, the mouse events works without problems. This is the code I am using:

TranslateTransform T = new TranslateTransform();

    public GameTitle()
    {
        InitializeComponent();

        Mouse.OverrideCursor = Cursors.None;
        this.MouseMove += GameTitle_MouseMove;

        CompositionTarget.Rendering +=CompositionTarget_Rendering;
    }

    void CompositionTarget_Rendering(object sender, EventArgs e)
    {
        CursorImage.RenderTransform = T;
    }

    void GameTitle_MouseMove(object sender, MouseEventArgs e)
    {
        T.X = e.GetPosition(this).X;
        T.Y = e.GetPosition(this).Y;
    }

This is with the image cursor:

Result

And this is without the image cursor and the mouse cursor hidden: enter image description here

How can I make the buttons works with the image cursor? Thanks in advance for your help!

Community
  • 1
  • 1
Exel Gamboa
  • 936
  • 1
  • 14
  • 25

1 Answers1

1

While I was writing the question, I keep searching for answers and I found this nice software (http://www.aha-soft.com/artcursors/cur-editor.htm) that helped me reading a PNG image and saving it as a Cursor (*.cur) file. Then I added the file to the project resources in Visual Studio and added the following code as described in one of the answer in https://stackoverflow.com/a/8715560/1278771:

Mouse.OverrideCursor = new Cursor(new System.IO.MemoryStream(MyNameSpace.Properties.Resources.TheResourceName));

Now, it works very nice!:

enter image description here

Community
  • 1
  • 1
Exel Gamboa
  • 936
  • 1
  • 14
  • 25