Member Avatar for nssltd

You know you'd think it be the easiest thing in the WORLD to change the cursor, after all its just an image but yet again i'm having problems.I am making a web browser project I have the standard cursor( . cur file ) and when the application is navigating i want it to show a custom ani file i made in axialis icon workshop but im not sure how to add it in to my project. so far i know i need to import user32.dll into my project. but so far thats it. Can any one help me?

Any help is much appreciated,

NSSLTD

The Cursor class does not support any animated cursors(ani files)
See this article for more info.

Member Avatar for nssltd

Seriously that is odd, so theres no way to use .ani's then. i was just wondering how windows did it then?

Member Avatar for nssltd

Dear users i have found out how to use animated cursors in c#
i found out the answer from this article here
here is the code i used
NOTE: blob is an animated cursor i created.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace anitest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            try
            {
                this.Cursor = AdvancedCursors.Create(Path.Combine(Application.StartupPath, "blob.ani"));
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        public class AdvancedCursors
        {

            [DllImport("User32.dll")]
            private static extern IntPtr LoadCursorFromFile(String str);

            public static Cursor Create(string filename)
            {
                IntPtr hCursor = LoadCursorFromFile(filename);

                if (!IntPtr.Zero.Equals(hCursor))
                {
                    return new Cursor(hCursor);
                }
                else
                {
                    throw new ApplicationException("Could not create cursor from file " + filename);
                }
            }

        }
    }
}

Use it wisely :D

NSSLTD

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.