Introduction:
As we know, the cursor is pointing to an area at
where it is placed. Now we are going to make an animated cursor as a custom
control. Firstly I would like to tell you what is animated cursor? An animation is a sequence of images, frames that is displayed over time. A cursor
which has some image like a moving ball and moving picture and any type of
icon you want on a cursor.
Now we are going to do this specific task which show how we can make a animated cursor-custom control in Visual Studio 2010. For an Animated
Cursor there is a special format named an .ANI file which is being used for
reading and storing the Windows Animated Cursor. It has a structure format named
as Microsoft RIFF that contains information about the animation( Author, Title, Steps, Length and order of each step).
Now we are going to create a animated curso :
Step 1: Open Visual Studio 2010 and create a window application named animated_cursor.

Step 2: Further, we have to add two Namespaces.
using System.IO;
using System.Runtime.InteropServices;Step 3: Now download a cursor image of format .ANI name as 7updot.ani.
Step 4: Right click on animated_cursor file and click to add existing file and select the image of cursor which you have loaded.
Step 5: After adding the .ANI file, further you are required to paste it into the bin folder of the project.

Step 6: Firstly look at the code of the class in which we import a dll file named user32.dll and create a static method.
Let
glimpse on a class code:
public
class AnimatedCurs
{
[DllImport("User32.dll")]
private static
extern IntPtr LoadCursorFromFile(String str);
public static
Cursor Create(string fname)
{
// how to handle cursor.
IntPtr HC = LoadCursorFromFile(fname);
// Check wheather it is succeeded or not.
if (!IntPtr.Zero.Equals(HC))
{
return new
Cursor(HC);
}
else
{
throw new
ApplicationException("cursor was not created from
file " + fname);
}
}
}
Step 7: Now look slightly code of form_load event in which is implementing Exception handling by using a try{} catch{} block and throwing an Exception in a class if it occurs.
Glimpse of form_load code:


Roberto LionPosted Jun 16, 2023, 4:33 AM
Is there a sample project to download?