Administrators PlausiblyDamp Posted May 13, 2004 Administrators Posted May 13, 2004 (edited) Little class inspired by a code snippet from Nerseus originally posted here this C# class will set the Cursor for a given form and reset it when the class is disposed - propbably best used with C#'s using function. Sample usage //following line will set the mouse pointer to the hourglass using (ChangeMousePointer c = new ChangeMousePointer(this)) { for (int i=0;i < 1000000; i++) Application.DoEvents(); } //cursor will be restored here The class also provides an overloaded constructor allowing you to specify which cursor is required. In a debug build the class runs slower as it will record which Method / File / Line it was allocated on (Using the StackTrace and StackFrame classes) and has a finalizer that checks we have been properly disposed - if not it will assert giving the relevant details about it's creation. In a release build all this information is removed and no Finalizer is emitted. Typical assert output is as follows ---- DEBUG ASSERTION FAILED ---- ---- Assert Short Message ---- ChangeMousePointer not disposed ---- Assert Long Message ---- Originally allocated Method : button2_Click File : c:\documents and settings\x\my documents\visual studio projects\windowsapplication7\form1.cs Line : 117 at ChangeMousePointer.Finalize() The class can be used for VB you just have to remember to call .Dispose manually (VB doesn't have the equivalent of C#'s using) Edit: In debug builds now asserts if the cursor has been changed to a different cursor in between the object being created and disposed.ChangeMousePointer.zip Edited May 13, 2004 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.