Jump to content
Xtreme .Net Talk

Recommended Posts

  • Administrators
Posted (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 by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...