Color cursor/animated cursor and custom cursor [turn] In. NET,. net cursor
The following is a complete example. You can use the command line compilation to see the effect. Test. csusing System; using System. drawing; using System. windows. forms; using System. runtime. interopServices; using System. reflection; namespace ColorCursor {// <summary> /// function of this example: // In. NET to achieve the color cursor, animation cursor and custom cursor. /// </Summary> public class Form1: System. windows. forms. form {[DllImport ("user32.dll")] public static extern IntPtr LoadCursorFromFile (string fileName); [DllImport ("user32.dll")] public static extern IntPtr SetCursor (IntPtr cursorHandle ); [DllImport ("user32.dll")] public static extern uint DestroyCursor (IntPtr cursorHandle); [STAThread] static void Main () {Application. run (new Form1 ();} public Form1 () {this. text = "Welcome to [wonderful world of the Meng xianhui Conference ]: http://dotnet.aspx.cc/ "; Cursor myCursor = new Cursor (Cursor. current. handle); // dinateu2.ani is the windows cursor: IntPtr colorCursorHandle = LoadCursorFromFile (@ "C:/WINNT/Cursors/dinateu2.ani"); myCursor. getType (). invokeMember ("handle", BindingFlags. public | BindingFlags. nonPublic | BindingFlags. instance | BindingFlags. setField, null, myCursor, new object [] {colorCursorHandle}); this. cursor = myCursor ;}}}
Create a Dynamic Cursor
Www3.emu-zone.org/host/EMUGIF/teach/teach23.htm
Tools used:
1. Ulead GIF Animator 5.05 (UGA5)
2. GIF Movie Gear 4.01 (GMG4)
First, let me explain the format of the cursor. In WINDOWS, the default cursor size is 32*32, which is too large or too small. In addition, each frame of the cursor must be filled with the entire canvas, otherwise, the system will automatically stretch the graph that does not meet the requirements and change its length and width to 32. This will cause the cursor to deform and affect the appearance.
Now, let's start making the cursor.
The production process is divided into two parts. First, edit the animation that you want to make into a light mark in UGA5. If you have a ready-made image, you can skip the UGA5 production process and directly view the GMG4 production process.
UGA5 production process:
1. Open UGA5 and create a new canvas. The canvas size is adjusted to 32*32. The canvas looks completely transparent ()
2. Draw the desired appearance of the optical table within the specified size range, or directly import the image ()
3. After the frame is completed, adjust the time of each frame. The frame movement mode must be set to "to the background", so that there will be no duplication or other phenomena during import in GMG4 ()
4. save the images separately, and save each frame as a single image so that the ratio of each image is equal to 32*32, if the animation is saved directly, the ratio of the first frame is 32*32, and the subsequent images are determined based on the object size in each frame, in this way, even if a dynamic cursor is made in GMG4, only the first frame can be kept unchanged, and the rest will be automatically stretched to 32*32 by the system.
The UGA5 production process ends here and is then transferred to GMG4.
GMG4 production process:
1. Import the newly created image (or prepare a picture that meets the requirements in advance), arrange it in order, check the proportion of the image, and test it.
2. After confirming that there is no problem, you can save it. select Save as in the file, and then select Save type as WINDOWS animation cursor ()
In addition, you need to select the cursor point in the following definition heat area when saving the cursor (the cursor in WINDOWS is used by the pointer front end for clicking, dragging, and other operations, what actually works is just a point at the front of the pointer. Here we use the position to locate this point.) If you look at it carefully, you can find that there is a flashing point in the center of the area, at this time, the mouse moves to the area and it will become a cross. Just click the place you want to use as the cursor and save it.
4. apply the completed cursor to WINDOWS, click Start> set> Control Panel> mouse> pointer, select the cursor you want to change, and click browse to find the completed cursor, then you can view the cursor you just made in the preview area in the upper right corner.
I am currently playing a hamster game, ''I made it using visual C # NET''. Now there is a question: how can I make the mouse a hammer'
// 1. Load the cur cursor file
Cursor = new Cursor (@ "E: \ Projects \ Test01 \ Test01 \ myCursor. cur ");
// 2. Load the image and set it to the cursor
Bitmap bm = (Bitmap) Image. FromFile (@ "E: \ Projects \ Test01 \ Test01 \ myPicture.jpg ");
Cursor = new Cursor (bm. GetHicon ());
// 3. Load the ani cursor file (you can also load the cursor file in the format of cur and ico)
// Here, we refer to Chapter E of Mencius to achieve a color cursor, an animated cursor, and a custom cursor in. NET.
// Add two references:
// Using System. Runtime. InteropServices;
// Using System. Reflection;
// Other:
// [DllImport ("user32.dll")]
// Public static extern IntPtr LoadCursorFromFile (string fileName );
// [DllImport ("user32.dll")]
// Public static extern IntPtr SetCursor (IntPtr cursorHandle );
// [DllImport ("user32.dll")]
// Public static extern uint DestroyCursor (IntPtr cursorHandle );
Cursor myCursor = new Cursor (Cursor. Current. Handle );
IntPtr colorCursorHandle = LoadCursorFromFile (@ "E: \ Projects \ Test01 \ Test01 \ myAni. ani ");
MyCursor. GetType (). InvokeMember ("handle", BindingFlags. Public |
BindingFlags. NonPublic | BindingFlags. Instance |
BindingFlags. SetField, null, myCursor,
New object [] {colorCursorHandle });
... The remaining full text>