Home All Groups Group Topic Archive Search About

How to Embed a Cursor

Author
19 Aug 2006 1:10 AM
bern11
How do you embed a cursor in a project and use it?  I created a cursor
in a project, I can use it using the Cursor(String) constructor, but I
cannot get it to work with the Cursor(Type,String) constructor. I'm
missing something really simple.

The resource view has an ID assigned to it, do I use that?

How do I re-assign the hot-spot?  (It is greyed-out in the properties
view and stuck at (0,0)).

Author
19 Aug 2006 9:18 PM
Dave Sexton
Hi,

> How do you embed a cursor in a project and use it?  I created a cursor in a project, I can use it using the Cursor(String)
> constructor, but I cannot get it to work with the Cursor(Type,String) constructor. I'm missing something really simple.
>
> The resource view has an ID assigned to it, do I use that?

The Type parameter is used to scope the embedded resource name.

If you are using Visual Studio.NET 2005 you can add a new Resource file to your project.  Once added, open the file and select
"Other" from the drop-down that appears under the list of tabs.  Then select "Add Existing File..." from the drop-down to its right.
Browse to your cursor file and add it to the resource file.  Now call a different constructor of the Cursor class that takes only a
Stream parameter just like this (assuming your resource file is named, "MyResourceFile" and your cursor is named, "MyCustomCursor"):

Cursor cursor;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(MyResourceFile.MyCustomCursor))
{
    cursor = new Cursor(stream);
}

If you are using an older version of Visual Studio.NET you can view the Properties Window, after selecting the cursor file in
Solution Explorer, and set "Build Action" to "Embedded Resource".  When you call the Cursor constructor pass in a Type that exists
in the same namespace as the cursor file.  In C# projects each namespace is a folder in the heirarchy of folders that contains the
cursor file, excluding the project folder itself (I'm not sure how this works in VB).  The name of the resource is the name of the
file and its extension.

Note that the Cursor class only supports black & white cursors:

(watch for wrapping)
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/53182cf1f8d8fcc5/74d09c617772f136?lnk=st&q=dotnet+Cursor+black+%26+white+color&rnum=2#74d09c617772f136

> How do I re-assign the hot-spot?  (It is greyed-out in the properties view and stuck at (0,0)).

In the "Image Editor" toolbar of VS.NET there is an icon that looks like a black arrow pointing at a spark.  That is the "Set Hot
Spot Tool".

--
Dave Sexton

AddThis Social Bookmark Button